<?php
error_reporting(E_ERROR|E_PARSE);
if (!class_exists("go_sql")){
	include("/var/www/html/open/conf/wsdl.le.je.ll");
	$le=new go_sql();
	$le->connect();
}
include("/var/www/html/open/fun_pft.php");
// include("price.fun.php");
class PFT_server {
	public $err1="101"; //无授权，拒绝连接
	public $err2="102"; //传输数据类型出错
	public $err3="103"; //传输数据格式出错
	public $err4="104"; //数据无法传输
	public $err5="105"; //数据为空或重叠
	public $err6="106"; // 数据服务出错，无法提交订单
	public $err7="107"; // 返回数据非XML格式
	public $err8="108"; // 网络中断
	public $err9="109"; // 重复查询
	public $err10="110"; // 重复提交
	public $err11="111"; // 数据含有非法字符
	public $err12="112"; // 手机格式错误
	public $err13="113"; // 错误的联票方式
	public $err14="114"; // 编码出错，无法继续
	public $err15="115"; // 网站服务出错，请联系技术开发人员
	public $err16="116"; // 短信重发次数过多
	public $err17="117"; // 在线支付未支付成功无法发短信
	public $err18="118"; // 终端信息出错，请联系技术人员
	public $err19="119"; // 订单状态出错，请联系技术人员
	public $err20="120"; // 订单号已超出系统承载，无法生成
	public $err201="1201"; // 凭证码生成错误，已超出系统承载
	public $err21="121"; // 状态参数出错
	public $err22="122"; // 资金账户余额不足
	public $err23="123"; // 未知的订单号
	public $err24="124"; // 权限不够

	public $err30="130"; // 邮件格式错误
	public $err31="131"; // 手机格式错误
	public $err32="132"; // 短信插入失败
	public $err33="133"; // 时间未到
	public $err34="134"; // 时间超过

	public $err41="141"; // 无修改返回
	public $err42="142"; // 存在时间交集
	public $err43="143"; // 未按照预期更新数据
	public $err44="144"; // 参加优惠计划的订单不支持修改订单
	public $err45="145"; // 修改订单内容不能全部为空
	
	public $err1061=1061; //无此日期的价格
	public $err1062=1062; //库存已售罄
	public $err1063=1063; //总库存已售罄
	public $err1064=1064; //错误的分销差价设置
	public $err1065=1065; //无此商品的分销价格
	public $err1066=1066; //商品票类数据出错
	public $err1067=1067; //商品数据出错
	public $err1068=1068; //商品需提前预定
	public $err1069=1069; //已超过当日购买的时间
	public $err1070=1070; //支付方式错误
	public $err1071=1071; //游玩时间必填
	public $err1072=1072; //取票人姓名、手机不能为空
	public $err1073=1073; //错误的供应链
	public $err1074=1074; //短信发送失败
	public $err1075=1075; //远端订单号不能重复
	public $err1076=1076; //过期的订单无法修改
	public $err1077=1077; //订单不是未使用状态，无法取消或修改
	public $err1078=1078; //订单修改数量只能减少，不能增加
	public $err1090=1090; //远端平台订单同步失败
	public $err1091=1091; //此产品有购买限制
	
	public $err2021=2021; //套票子票产品设置错误
	public $err2022=2022; //套票产品无法单独取消
	public $err2023=2023; //套票部分产品已经使用或状态错误
	
	public $err3000=3000; //产品抓取ID不能为空
	public $err3001=3001; //产品抓取地址无效
	public $err3002=3002; //产品抓取通知地址无效
	public $err3003=3003; //产品抓取设定错误
	public $err3004=3004; //产品抓取地址或通知地址为空
	public $err3005=3005; //禁止使用同接口服务器一样的地址
	
	public $err4001=4001; //【自助取票】查询需要必要的参数（景区编码）
	public $err4002=4002; //【自助取票】不能查询非自供的订单
	public $err4003=4003; //【自助取票】无权限操作回调接口
	public $err4004=4004; //【自助取票】订单号错误或无权限修改
	
	public $err5001=5001; //景点无场次或无座位
	public $err5002=5002; //因场次或座位的时间问题无法修改订单
	
	public $t1="uu_land";
    public $t2="uu_jq_ticket";
	public $t3="uu_ticket_pprice";
	public $t4="uu_jq_order";
	public $t5="uu_area";
	public $t6="uu_order_trace";
	public $t7="uu_ss_order";
	
    //private $auth=false;

//验证身份
	public function authrize($ac, $pw){
		$ac=urlencode($ac);
		$pw=urlencode($pw);
	
	    $str="select id,vtype,lang,qx from dataex where account=\"".$ac."\" and pwd=\"".$pw."\" and vtype=0 limit 1";
        $GLOBALS['le']->query($str);
	    if ($GLOBALS['le']->fetch_assoc()) {
			$this->vtype=$GLOBALS['le']->f('vtype');
			$this->lang=$GLOBALS['le']->f('lang');
			$this->ac_qx=$GLOBALS['le']->f('qx');
			return true;
		}else{
			return false;
		}
	}
//景区列表
	public function Get_ScenicSpot_List($ac, $pw, $n=NULL, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("Get_ScenicSpot_List#ac:$ac, pw:$pw, n:$n, m:$m");
		$str="select id from pft_member where account='$ac' and status=0";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$fxs_id=$GLOBALS['le']->f('id');
		
		$aland=array();
		
		//自供自销
		$str="select f.lid,t.apply_did as aid from uu_jq_ticket as t left join uu_land_f as f on t.id=f.tid left join uu_products p on p.id=t.pid where p.p_status=0 and p.apply_limit=1 and t.apply_did=$fxs_id group by f.lid";
		$GLOBALS['le']->query($str);
		while ($GLOBALS['le']->fetch_assoc()) {
			$aland[]=$GLOBALS['le']->f('lid').','.$GLOBALS['le']->f('aid');
		}
		
		//$alandstr=implode(',',$aland);
		
		//直销可购买的产品
		$str="select pids,aid from pft_product_sale_list where fid=$fxs_id and status=0";
		$GLOBALS['le']->query($str);
		$a_pids=array();
		while ($row=$GLOBALS['le']->fetch_assoc()) {
			$a_pids[]=$row;
		}
		// print_r($a_pids);exit;
				// echo $str;exit;
		foreach ($a_pids as $k=>$v){
			if ($v['pids']=='A'){
				$str="select f.lid,t.apply_did as aid from uu_jq_ticket as t left join uu_land_f as f on t.id=f.tid left join uu_products p on p.id=t.pid where p.p_status=0 and p.apply_limit=1 and t.apply_did=".$v['aid']." group by f.lid";
				$GLOBALS['le']->query($str);
				while ($GLOBALS['le']->fetch_assoc()) {
					$aland[]=$GLOBALS['le']->f('lid').','.$GLOBALS['le']->f('aid');
				}
			}elseif($v['pids']){
				$str="select f.lid,t.apply_did as aid from uu_jq_ticket as t left join uu_land_f as f on t.id=f.tid left join uu_products p on p.id=t.pid where p.p_status=0 and p.apply_limit=1 and t.pid in (".$v['pids'].") group by f.lid";
				$GLOBALS['le']->query($str);
				while ($GLOBALS['le']->fetch_assoc()) {
					$aland[]=$GLOBALS['le']->f('lid').','.$GLOBALS['le']->f('aid');
				}					
			}
			
		}
		
		//转分销可购买的产品
		$str="select pid,sid from pft_p_apply_evolute where fid='$fxs_id' and status=0";
		$GLOBALS['le']->query($str);
		$evo_pids=array();
		while ($row=$GLOBALS['le']->fetch_assoc()) {
			$evo_pids[]=$row;
		}
		
		foreach ($evo_pids as $k=>$v){
			$str="select f.lid,t.apply_did as aid from uu_jq_ticket as t left join uu_land_f as f on t.id=f.tid left join uu_products p on p.id=t.pid where p.p_status=0 and p.apply_limit=1 and t.pid=".$v['pid']." group by f.lid";
			$GLOBALS['le']->query($str);
			while ($GLOBALS['le']->fetch_assoc()) {
				$aland[]=$GLOBALS['le']->f('lid').','.$v['sid'];
			}				
		}print_r($aland);exit;
		//剔除重复的
		$alandU=array_unique($aland);		
		if (!$alandU) return errXML($this->err5);
		
		$a1=array();
		$arrL=array();
		$arrA=array();
		foreach ($alandU as $val) {
			$arrL[]=current(explode(',',$val));
			$arrA[]=end(explode(',',$val));		
		}
		$alandstr=implode(',',$arrL);
		$str="select id,title,addtime,imgpath,area,p_type from ".$this->t1." where id in ($alandstr) order by px desc";
		if ($n) $str.=" limit ".$n;
		if ($m && $n) $str.=",$m";
        $GLOBALS['le']->query($str);
		while ($row=$GLOBALS['le']->fetch_assoc()) {
         $a1[]=$row;
		}
		//return $str;
		if (count($a1)<1) {
		    return errXML($this->err5);
		}else{
			foreach ($a1 as $key=>$val){  
				$kword=$val[area];
				$akword=explode("|",$kword);
				$apword=array();
			  
				$str="select area_name from ".$this->t5." where area_id='".$akword[0]."' or area_id='".$akword[1]."' or area_id='".$akword[2]."'";
				$GLOBALS['le']->query($str);
				while ($GLOBALS['le']->fetch_assoc()) {
					$apword[]=$GLOBALS['le']->f('area_name');
				}
			  //return implode('|',$apword);
				$a1[$key]['area']=implode('|',$apword);			  
			 }
			 print_r($a1);exit;
		     return toXML($this->lang,$a1);
		   }
		
		}else{
			return errXML($this->err1);
		}

    }

//景区详细
	public function Get_ScenicSpot_Info($ac, $pw, $n) {

		if ($this->authrize($ac, $pw)){
		$this->logrec("Get_ScenicSpot_Info#ac:$ac, pw:$pw, n:$n, m:$m");
		$a2=array();
		$str="select id,salerid,title,tel,fax,jtype,opentime,runtime,area,address,imgpath,jqts,p_type,jtzn,bhjq from ".$this->t1." where id='$n'";

        $GLOBALS['le']->query($str);
		while ($row=$GLOBALS['le']->fetch_assoc()) {
         $a2[]=$row;
		}
		//return $str;
		if (count($a2)<1) return errXML($this->err5);
		else return toXML($this->lang,$a2);
		}else{
			return errXML($this->err1);	
		}

    }

//门票查询
	public function Get_Ticket_List($ac, $pw, $n=NULL, $m=NULL) {
		
		if ($this->authrize($ac, $pw)){
			$this->logrec("Get_Ticket_List#ac:$ac, pw:$pw, n:$n, m:$m");
			
			if (!$n && !$m) return errXML($this->err5);	
			$a3=array();
			$str="select f.lid,t.id,t.title,t.pid,t.delaydays,t.notes,t.ddays,t.reb,t.reb_type,f.dhour,f.startplace,f.endplace,f.tourist_info,f.ass_station,f.series_model,t.apply_did as aid,t.tprice,t.pay,t.buy_limit_up,t.buy_limit_low from ".$this->t2." as t left join uu_land_f as f on t.id=f.tid left join uu_products p on p.id=t.pid where p.p_status=0 and p.apply_limit=1";
			if ($m) $str.=" and t.id='".(int)$m."'";
			else $str.=" and t.landid='$n'";
			$str.=" order by t.px desc";
			// echo $str;exit;
			$GLOBALS['le']->query($str);
			while ($row=$GLOBALS['le']->fetch_assoc()) {
			 $a3[]=$row;
			}
			
			$str="select id,dname from pft_member where account='$ac' and status=0";
			$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
			$member=$GLOBALS['le']->f('id');
			$dname=$GLOBALS['le']->f('dname');
			// echo $member;

			//需要剔除掉无权限购买的
			foreach ($a3 as $k=>$v){
				//$dprice=0;
				$aid=$v['aid'];
				$pid=$v['pid'];			
				$flag=0;
				if ($aid!=$member){
					//判断是否可以购买此供应商下的产品
					$str="select pids from pft_product_sale_list where fid=$member and aid=$aid and status=0 limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$pids=$GLOBALS['le']->f('pids');
					if ($pids!='A'){
						$a_pids=explode(',',$pids);
						// echo $pid ;
						// print_r($a_pids);exit;
						if (in_array($pid,$a_pids)) $flag=0;
					}
					else $flag=1;
				}
				else $flag=1;
				
				//return $flag;
				if ($flag==0) unset($a3[$k]);
				
				$str="select sid from pft_p_apply_evolute where pid='$pid' and fid='$member' and status=0";
				$GLOBALS['le']->query($str);
				while ($GLOBALS['le']->fetch_assoc()) {
					//插入记录
					$v['aid']=$GLOBALS['le']->f('sid');
					$a3[]=$v;
				}
			}
			print_r($a3);exit;
			if (count($a3)<1) return errXML($this->err5);		
			else return toXML($this->lang,$a3);
		}
		else{
			return errXML($this->err1);	
		}

    }

//[接口]动态价格、库存上限获取 产品ID，日期，模式[1单个价格 2单个最低价]，类型[0分销价 1零售价]，获取当日库存上限返回-1无限
	public function Dynamic_Price_And_Storage($ac, $pw, $pid, $date='', $mode=0, $ptype=0, $get_storage=0, $m) {
		if ($pw=='C83194C8E56157238B1B' || $this->authrize($ac, $pw)){
		$this->logrec("Dynamic_Price_And_Storage#TIGER#ac:$ac, pw:$pw, pid:$pid, date:$date, mode:$mode, ptype:$ptype, get_storage:$get_storage, m:$m");
		if (is_numeric($pid)===false) return $this->err3;
		$a5=array();
		$a51=array();
		$ex_price=0;
		
		require_once("/var/www/html/new/conf/pft_tiger.ll"); 
		$Tiger=new Tsql();
		$Tiger->connect();
		
		if ($ptype==0) {
			$str="select id from pft_member where account='$ac' and status=0 limit 1";
			$Tiger->query($str);
			if (!$Tiger->fetch_assoc()) return errXML($this->err1);
			$fxs_id=$Tiger->f('id');
			
			//判断是否是自己供应的产品
			$str="select apply_did from ".$this->t2." where pid='$pid' limit 1";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$apply_did=$Tiger->f('apply_did');
			if ($apply_did!=$fxs_id){
				//判断是否可以购买此供应商下的产品
				$str="select pids from pft_product_sale_list where fid=$fxs_id and aid=$apply_did and status=0 limit 1";
				$Tiger->query($str);
				$Tiger->fetch_assoc();
				$pids=$Tiger->f('pids');
				$flag=0;
				if ($pids!='A'){
					$a_pids=explode(',',$pids);
					if (!in_array($pid,$a_pids)) $flag=1;
				}
	
				$str="select aids from pft_p_apply_evolute where pid='$pid' and fid='$fxs_id' and sid='$m' and status=0 limit 1";
				$Tiger->query($str);
				$Tiger->fetch_assoc();
				$aids=$Tiger->f('aids');
				if (!$aids) $flag2=1;
				else $flag2=0;
				
				if ($flag==1 && $flag2==1) return errXML($this->err1065);
				
				$arr_aids=explode(',',$aids);
				
				$ci=count($arr_aids);
				
				for ($i=0;$i<$ci;$i++){
					if ($i==0) continue;
					$j=$i-1;
					if ($i==1) {
						//取得此分销商的差价
						$str="select dprice from uu_priceset where tid='$pid' and pid='".$arr_aids[$i]."' and aid=0 limit 1";
						$Tiger->query($str);
						$Tiger->fetch_assoc();	
						$aid_dprice=$Tiger->f('dprice');						
						//分销联盟会员折扣1
						if ($this->PFT_D_Union_ZK_SE($apply_did,$arr_aids[$i])) $aid_dprice=0;
						if (!$aid_dprice || $aid_dprice<0) $aid_dprice=0;
					}else{								
						//计算供应商应扣多少钱
						$str="select dprice from uu_priceset where tid='$pid' and pid='".$arr_aids[$i]."' and aid='".$arr_aids[$j]."' limit 1";
						$Tiger->query($str);
						$Tiger->fetch_assoc();	
						$aid_dprice=$Tiger->f('dprice');
						//分销联盟会员折扣2
						if ($this->PFT_D_Union_ZK_SE($arr_aids[$j],$arr_aids[$i])) $aid_dprice=0;
						if (!$aid_dprice || $aid_dprice<0) $aid_dprice=0;					
					}
					//增量价格
					$ex_price+=$aid_dprice;
					//$per_price=$f_price+$ex_price;
					//记录per_price
				}
	
				$j++;
				$last_apply_did=$arr_aids[$j]?$arr_aids[$j]:0;
				$str="select dprice from uu_priceset where tid='$pid' and pid='".$fxs_id."' and aid='".$last_apply_did."' limit 1";
				$Tiger->query($str);
				if (!$Tiger->fetch_assoc()) $tt_dprice=0;
				else $tt_dprice=$Tiger->f('dprice');
				//分销联盟会员折扣3
				$LM_apply_did=$arr_aids[$j]?$arr_aids[$j]:$apply_did;
				if ($this->PFT_D_Union_ZK_SE($LM_apply_did,$fxs_id)) $tt_dprice=0;		
				if (!$tt_dprice || $tt_dprice<0) $tt_dprice=0;				
				$ex_price+=$tt_dprice;	
			}else{
				$ex_price=0;
			}
		}
		
		//取单个价格
		$dprice=$ex_price;
		$onday=date('w',strtotime($date));
		if ($mode==1 && $date){
			//特殊日价格
			$q_s_price=($ptype==0)?'s_price':'l_price as s_price';
			$str="select $q_s_price,storage from uu_product_price where start_date<='$date' and end_date>='$date' and pid=$pid and ptype=1 and string_bj(weekdays,$onday)=1 order by id desc limit 1";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$s_price=$Tiger->f('s_price');
			$storage=$Tiger->f('storage');
			if (is_numeric($s_price)) {
				$tprice=$s_price+$dprice;
				$tprice=($ptype==0)?$tprice:$s_price;
				//$tprice=round($tprice/100,2);
				$a51['sprice']=$tprice;
				if ($get_storage==1) $a51['storage']=$storage;
				$a5[]=$a51;
				return toXML($this->lang,$a5); 
			}
			
			$q_s_price=($ptype==0)?'n_price':'l_price as n_price';
			$str="select $q_s_price,storage from uu_product_price where start_date<='$date' and end_date>='$date' and pid=$pid and ptype=0 and string_bj(weekdays,$onday)=1 order by id desc limit 1";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$n_price=$Tiger->f('n_price');
			$storage=$Tiger->f('storage');
			if (is_numeric($n_price)) {
				$tprice=$n_price+$dprice;			
				$tprice=($ptype==0)?$tprice:$n_price;
				//$tprice=round($tprice/100,2);
				$a51['sprice']=$tprice;
				if ($get_storage==1) $a51['storage']=$storage;
				$a5[]=$a51;
				return toXML($this->lang,$a5); 
			}
			
			return errXML($this->err5);
		}elseif($mode==2){
			//单个有效最低价
			$q_s_price=($ptype==0)?'s_price':'l_price';
			$str="select min($q_s_price) as mp from uu_product_price where date_add(end_date,interval 1 day)>now() and pid=$pid and $q_s_price>=0";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$mp=$Tiger->f('mp');
			
			$q_s_price=($ptype==0)?'n_price':'l_price';
			$str="select min($q_s_price) as np from uu_product_price where date_add(end_date,interval 1 day)>now() and pid=$pid and $q_s_price>=0";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$np=$Tiger->f('np');
			
			if ($mp===NULL && $np!==NULL) $lp=$np;
			elseif ($np===NULL && $mp!==NULL) $lp=$mp;
			elseif ($mp!==NULL && $np!==NULL) $lp=($mp>$np)?$np:$mp;
			//if (is_numeric($lp) && $lp>=0) return $lp;
			else $lp=-1;

			if (is_numeric($lp) && $lp>=0) {
				$tprice=$lp+$dprice;			
				$tprice=($ptype==0)?$tprice:$lp;
				//$tprice=round($tprice/100,2);
				$a51['sprice']=$tprice;
				$a5[]=$a51;
				return toXML($this->lang,$a5); 
			}
			return errXML($this->err5);
		}
		/* else{
			$str="select id,pid,ptype,n_price,s_price,l_price,start_date,end_date,memo,weekdays,storage from uu_product_price where pid=$pid";
			if ($sdate!=='' && $edate!=='') $str.=" and greatest(start_date,'$sdate')<=least(end_date,'$edate')";
			$str.=" order by id desc";
			//$a5[]=array("fprice"=>$fprice);
        	$GLOBALS['le']->query($str);
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}			
			return toXML($this->lang,$a5);
			作废需要到内部接口搬
		} */
		return errXML($this->err5);
		}else{
		return errXML($this->err1);	
		}

    }	
	

/*票付通平台订单接口 （外部）
2景区ID,3票类ID,远端订单号,单价(分单位),数量,游玩时间,取票人姓名,取票人手机,联系人手机,是否发送短信1不发送,支付方式（0账户余额支付2使用供应商处金额支付）,下单方式（0正常下单 1手机用户下单 注：手机用户下单可以用取票人手机当作登录号登入票付通系统）,集合地点,团号,供应商ID）
*/
	public function PFT_Order_Submit($ac, $pw, $lid, $tid, $remotenum=0, $tprice, $tnum, $playtime, $ordername, $ordertel, $contactTEL, $smsSend=0, $paymode=0, $ordermode=0, $assembly=0, $series='', $concatID, $pCode, $m=NULL, $personID=NULL) {
		if ($this->authrize($ac, $pw)){
		
		$this->logrec("PFT_Order_Submit#ac:$ac, pw:$pw, lid:$lid, tid:$tid, remotenum:$remotenum, tprice:$tprice, tnum:$tnum, playtime:$playtime, ordername:$ordername, ordertel:$ordertel, contactTEL:$contactTEL, smsSend:$smsSend, paymode:$paymode, ordermode:$ordermode, assembly:$assembly, series:$series, concatID:$concatID, pCode:$pCode, personID:$personID");
		
		$concatID=0;
		$pCode=0;
		$unionCheck=0;
		if (!$personID) $personID=0;
		if ($paymode!=0 && $paymode!=2 && $paymode!=4) return errXML($this->err1070);
		if (!is_numeric($lid) || !is_numeric($tid) || $tnum<=0 || !is_numeric($tprice)) return errXML($this->err3);
		if (!$playtime) return errXML($this->err1071);
		if (!$ordername || !$ordertel) return errXML($this->err1072);
		
		//判断是否为套票
		$str="select p_type,terminal_type from uu_land where id='$lid' limit 1";
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$l_p_type=$GLOBALS['le']->f('p_type');
		$terminal_type=$GLOBALS['le']->f('terminal_type');
		if ($l_p_type=='F') $pCode=1;
		
		if ($terminal_type==0) {
			require_once("../conf/pg.le.je");
			$lee = new pgconn();
			$lee->getConn();
		}
		
		$str="select id,dname,dcodeURL from pft_member where account='$ac' and status=0 limit 1";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$member=$GLOBALS['le']->f('id');
		$dname=$GLOBALS['le']->f('dname');
		$dcodeURL=$GLOBALS['le']->f('dcodeURL');
		
		//判断远端订单号是否重复
		if ($remotenum){
			$str="select ordernum,code,salerid from ".$this->t7." where status<>3 and remotenum='$remotenum' and member='$member' order by id desc limit 1";
			$GLOBALS['le']->query($str);
			if ($GLOBALS['le']->fetch_assoc()) {
				$ordern=$GLOBALS['le']->f('ordernum');
				$code_url="http://12301.cc/".$this->sms_qrcode_url($ordern);
				$code=$GLOBALS['le']->f('code');
				$salerid=$GLOBALS['le']->f('salerid');
				$certString=$this->Make_Qrcode($code);
				$img_url="http://121.199.25.173/open/qr?".$certString;			
				$a51=array('ordernum'=>$ordern,'remotenum'=>$remotenum,'code'=>$code,'qrcodeURL'=>$code_url,'qrcodeIMG'=>$img_url);
				return errXML($this->err1075,$a51);
			}
		}

		//判断是否有此产品
		$str="select id,salerid,title,p_type from ".$this->t1." where id='$lid' limit 1";
		$GLOBALS['le']->query($str);
		$ajq=$GLOBALS['le']->fetch_assoc();
		if (!$ajq) return errXML($this->err1067);
		$salerid=$ajq['salerid'];
		
		$str="select title,delaydays,ddays,getaddr,apply_did,storage_open,storage,pid,delaytype,order_end,order_start,order_limit,sync_id,sync_status,pay,Mdetails,Mpath,buy_limit_up,buy_limit_low from ".$this->t2." where id='$tid' and landid='$lid' limit 1";
        $GLOBALS['le']->query($str);
		if (!$atk=$GLOBALS['le']->fetch_assoc()) return errXML($this->err1066);
		$aid=$apply_did=$atk['apply_did'];
		if (!$aid) return errXML($this->err1073);
		if ($member==$aid && $paymode!=4) $paymode=3;
		$storage=$atk['storage'];
		$delaytype=$atk['delaytype']; //开始时间类型0游玩时间1下单时间
		$order_start=$atk['order_start']; //订单开始时间
		$order_end=$atk['order_end']; //订单截至时间
		$order_limit=$atk['order_limit']; //订单验证限制日期
		$pid=$atk['pid'];
		$delaydays=$atk['delaydays'];
		$ttitle=$atk['title'];
		$storage_open=$atk['storage_open'];
		$sync_status=$atk['sync_status'];
		$sync_id=$atk['sync_id'];
		$ticket_pay=$atk['pay'];
		$Mdetails=$atk['Mdetails'];//开启类别功能
		$Mpath=$atk['Mpath'];
		$buy_limit_up=$atk['buy_limit_up'];
		$buy_limit_low=$atk['buy_limit_low'];
		
		if ($tnum>$buy_limit_up && $buy_limit_up!=0) return errXML($this->err1091);
		if ($tnum<$buy_limit_low && $buy_limit_low!=0) return errXML($this->err1091);
		
		$str="select id from uu_products where id='$pid' and apply_limit=1 and p_status=0 limit 1";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1066);	

		if ($l_p_type=='F') {
			//套票订单需要做子票的预置判定
			$m_aid=$m?$m:$aid;
			$coupon_CHK=$this->PFT_Coupon_Pre_Check($pid, $member, $m_aid, $playtime, $tnum);
			if ($coupon_CHK!=200) return errXML($this->err2021);
		}
				
		$dprice=0;
		if ($member!=$aid && ($aid==$m || !$m)){
			//判断是否可以购买此供应商下的产品
			$str="select pids from pft_product_sale_list where fid=$member and aid=$aid and status=0 limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$pids=$GLOBALS['le']->f('pids');
			if ($pids!='A'){
				$a_pids=explode(',',$pids);
				if (!in_array($pid,$a_pids)) return errXML($this->err24);
			}
		}

		//取得动态供货价
		$ddprice=$this->get_Dynamic_Price_Merge($pid, $playtime, 1, '', '', 0, 1);			
		if ($ddprice==-1) return errXML($this->err1061);
		
		$a_ddprice=explode(',',$ddprice);
		$ddprice=$a_ddprice[0];
		$ddstorage=$a_ddprice[1];
		if ($ddstorage!=-1) {
			//获取实时库存
			$dcstorage=$this->Dynamic_Storage_Check($tid, 1, $playtime, NULL, 1);
			$a_dcstorage=explode('|',$dcstorage);
			$d_cstorage=$a_dcstorage[1];
			$d_cstorage=(int)$d_cstorage+$tnum;
			
			if ($d_cstorage>$ddstorage) return errXML($this->err1062);			
		}
		
		if ($storage!=-1){
			//获取实时总库存
			$t_storage=$this->Dynamic_Storage_Check($tid, 2, NULL, $storage_open, 1);	
			//$t_storage=(int)$t_storage+$tnum;
			if ($t_storage>$storage) return errXML($this->err1063);			
		}
		
		if ($atk['ddays']!=0){
			$nowtime=strtotime(date('Y-m-d'));
			$ddays=$atk['ddays'];
			$excepttime=strtotime("+$ddays days",$nowtime);
			$s_playtime=strtotime($playtime);
			
			if ($s_playtime<$excepttime) return errXML($this->err1068);
 			if ($s_playtime==$excepttime){
				$str="select dhour from uu_land_f where pid='$pid'";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$dhour=$GLOBALS['le']->f('dhour');
				$nowhour=date("H:i:s");
				if ($dhour<$nowhour) return errXML($this->err1069);
			}	
		}

		//二手供应商扣钱记录
		$aids='';
		$a_aids_price=array();
		if ($m!=$aid && $m){			
			$str="select aids from pft_p_apply_evolute where pid='$pid' and fid='$member' and sid=$m and status=0 limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$aids=$GLOBALS['le']->f('aids');
			if (!$aids) return errXML($this->err5);
			
			$f_price=$this->get_Dynamic_Price_Merge($pid, $playtime, 1);
			if ($f_price==-1) return errXML($this->err1061);
			$arr_aids=explode(',',$aids);
			
			$ci=count($arr_aids);
			//$ci--;
			$a_a_money=array();
			$ex_price=0;
			for ($i=0;$i<$ci;$i++){
				if ($i==0) continue;
				$j=$i-1;
				if ($i==1) {
					//取得此分销商的差价
					$str="select dprice from uu_priceset where tid='$pid' and pid='".$arr_aids[$i]."' and aid=0 limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();	
					$aid_dprice=$GLOBALS['le']->f('dprice');
					//订单分销联盟1-外部
					if ($this->PFT_D_Union_ZK_SE($apply_did,$arr_aids[$i])) {
						$aid_dprice=0;
						$unionCheck=1;
					}
					if (!$aid_dprice || $aid_dprice<0) $aid_dprice=0;
				}else{								
					//计算供应商应扣多少钱
					$str="select dprice from uu_priceset where tid='$pid' and pid='".$arr_aids[$i]."' and aid='".$arr_aids[$j]."' limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();	
					$aid_dprice=$GLOBALS['le']->f('dprice');
					if (!$aid_dprice) $aid_dprice=0;
					//订单分销联盟2-外部
					if ($this->PFT_D_Union_ZK_SE($arr_aids[$j],$arr_aids[$i])) {
						$aid_dprice=0;
						$unionCheck=1;
					}
					if (!$aid_dprice || $aid_dprice<0) $aid_dprice=0;
				}
				$ex_price+=$aid_dprice;
				$per_price=$f_price+$ex_price;
				//记录per_price
				$a_aids_price[]=$per_price;
				
				$c_money=$per_price*$tnum;
				//查看信用额度和帐号余额
				$str="select kmoney,basecredit from pft_member_credit where fid='".$arr_aids[$i]."' and aid='".$arr_aids[$j]."' limit 1";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$kmoney=$GLOBALS['le']->f('kmoney');
				$basecredit=$GLOBALS['le']->f('basecredit');
				$kmoney+=$basecredit;
				
				if ($c_money>$kmoney) {
					$str="select amoney from pft_member_money where fid='".$arr_aids[$i]."'";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$amoney1=$GLOBALS['le']->f('amoney');
					if ($c_money>$amoney1) return errXML($this->err22);
					else {
					$a_a_money[]=array($arr_aids[$i],1,0,$c_money);
					$a_a_money[]=array($arr_aids[$j],1,1,$c_money);
					}
				}else{					
					$a_a_money[]=array($arr_aids[$i],0,0,$c_money,$arr_aids[$j]);//fid,信用额度,减,金额,aid
				}		
			}
			
			$fx_name=$arr_aids[1];
			$str="select dname from pft_member where id='$fx_name'";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$dname=$GLOBALS['le']->f('dname');
		}

		//订单分销联盟3-外部
		// $dprice_zk=$this->PFT_D_Union_ZK($m,$member);
		// if ($dprice_zk!='NONE') {
		$XML=$this->Dynamic_Price_And_Storage($ac,'C83194C8E56157238B1B',$pid,$playtime,1,0,0,$m);
		$Obj=simpleXML_load_string($XML);
		$tprice=(int)$Obj->Rec->UUsprice;
		// }	

		$totalmoney=$tprice*$tnum;
		
		//$begintime, $endtime
		$begintime=$playtime;
		if ($delaytype==1) $begintime=date("Y-m-d H:i:s");
		$end_ptime0=strtotime($begintime);
		$end_ptime1=strtotime("+".$delaydays." day",$end_ptime0);
		$endtime=date("Y-m-d",$end_ptime1);
		$endtime.=" 23:59:59";		
		if ($order_start) $begintime=$order_start;
		if ($order_end) $endtime=$order_end;
		if ($begintime=='0000-00-00 00:00:00' || $endtime=='0000-00-00 00:00:00') return errXML(1034);
		
		$aid=($m)?$m:$aid;
		
		//判断金额是否充足,下单成功后将扣除金额
		if ($paymode==0){
			$str="select amoney from pft_member_money where fid=$member limit 1";
        	$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err22);
			$amoney=$GLOBALS['le']->f('amoney');
			if ($totalmoney>$amoney) return errXML($this->err22);
		}elseif($paymode==2){
			$str="select basecredit,kmoney from pft_member_credit where fid=$member and aid=$aid limit 1";
        	$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err22);
			$kmoney=$GLOBALS['le']->f('kmoney');
			$basecredit=$GLOBALS['le']->f('basecredit');
			$Kkmoney=$kmoney+$basecredit;
			if ($totalmoney>$Kkmoney) return errXML($this->err22);
		}
		if ($this->PFT_D_Union_ZK_SE($aid,$member)) $unionCheck=1;

		//生成凭证码
		$ch1=100000; //标尺1
		$ch1_s=600000;//特殊标尺2015-02-02添加
		$ch2=800000; //标尺2
		$ch3=1000000; //标尺3
		if ($pCode==1){
			$str="select certnum as mid from ".$this->t7." s left join uu_order_addon a on s.ordernum=a.orderid where a.ifpack=1 and s.status<>4 and s.certnum>=".$ch2." and s.certnum<".$ch3;
			$str.=" order by s.id desc limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$mid=$GLOBALS['le']->f('mid');

			if (!$mid) $mid=$ch2;
			$mid=$mid+59;
			if ($mid>=$ch3) $mid=$ch2;
		}else{
			$str="select certnum as mid from ".$this->t7." where salerid='".$salerid."' and status<>4 and certnum>=".$ch1." and certnum<".$ch1_s;
			$str.=" order by id desc limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$mid=$GLOBALS['le']->f('mid');

			if (!$mid) $mid=$ch1;
			$mid=$mid+59;
			if ($mid>=$ch1_s) $mid=$ch1;

/* 			//回收机制
			$str="select id,ordernum from ".$this->t7." where status<>4 and status<>0 and certnum='$mid' and salerid='".$salerid."'";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$kill_id=$GLOBALS['le']->f('id');
			$kill_ordernum=$GLOBALS['le']->f('ordernum');
			if ($kill_id){
				$str="update ".$this->t7." set status=4 where id='$kill_id'";
				$GLOBALS['le']->query($str);
				$pstr="update order_info set order_state=7 where id=$kill_ordernum";
				$lee->pgquery($pstr);
			} */
		}

		//订单集合地点、支付状态等等
		$str="select ass_station,v_time_limit from uu_land_f where pid='$pid' limit 1";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$ass_station=$GLOBALS['le']->f('ass_station');
		$v_time_limit=$GLOBALS['le']->f('v_time_limit');
		$aass=unserialize($ass_station);
		$assembly_place=$aass[$assembly];
		
		//分销平台-》票付通订单搬迁
		$ex_series=explode('_',$series);
		if ($ex_series[0]=='pftXmove') $mid=$ex_series[1];

		//构造凭证号
		if ($pCode==1) $cert=hashstr((string)$mid, '987654');
		else $cert=hashstr((string)$mid, $salerid);
		
		// 查看是否是同步产品 同步产品将从远端获取凭证号
/* 		if ($sync_status==1 || $sync_status==2){
			$urlStr='http://open.16u.com/PFTtoUU_order_sync_INS.php?';
			$arrUrl=array();
			$arrUrl['tid']=$tid;
			$arrUrl['lid']=$lid;
			$arrUrl['begintime']=$begintime;
			$arrUrl['endtime']=$endtime;
			$arrUrl['tnum']=$tnum;
			$arrUrl['tprice']=$tprice;
			$arrUrl['ordername']=$ordername;
			$arrUrl['ordertel']=$ordertel;
			$arrUrl['concatID']=$concatID;
			$arrUrl['paymode']=$paymode;
			$urlStr.=http_build_query($arrUrl);
			$ret_remote=file_get_contents($urlStr);
			if (stripos($ret_remote,'|')>0) {
				$arr_r_ordern=explode('|',$ret_remote);
				$remote_ordern=$arr_r_ordern[0];//下单结束需要
				$cert=$arr_r_ordern[1];
			}else{
				return errXML($this->err1090);
			}
		} */

		//订单号生成
		//$str="select max(id) as mid from ".$this->t7." where date_format(ordertime,'%y%m')='".$y."'";
		$str="select max(id) as mid from ".$this->t7;
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$orderid=$GLOBALS['le']->f('mid');
		$orderid=$orderid?($orderid+100000):100000;
		$ordern=$orderid;

		//检测订单号是否存在
/* 		$str="select id from ".$this->t7." where ordernum='$ordern' limit 1";
		$GLOBALS['le']->query($str);
		if ($GLOBALS['le']->fetch_assoc()) {
			$chk_order_i=0;
			do {
				$ordern++;
				$str="select id from ".$this->t7." where ordernum='$ordern' limit 1";
				$GLOBALS['le']->query($str);
				if ($GLOBALS['le']->fetch_assoc()) {
					continue;
				}
				else break;
				$chk_order_i++;
			}while($chk_order_i<100);
		} */
		//支付状态
		$pay_status=($paymode==1)?2:1;
		//if ($paymode==4) $pay_status=0;
		if ($paymode==4) $pay_status=0;
		if ($ticket_pay==0) $pay_status=0;
		// 类别功能模块检校
		if ($Mdetails==1) {
			$Mseries=json_decode($series,true);
			$VenueID=$Mseries[0]?$Mseries[0]:'';
			$RoundID=$Mseries[1]?$Mseries[1]:'';
			$AreaID=$Mseries[2]?$Mseries[2]:'';
			$SeatID=$Mseries[3]?$Mseries[3]:'';
			$MUrl=array();
			$MUrl['VenueID']=$VenueID;
			$MUrl['RoundID']=$RoundID;
			$MUrl['AreaID']=$AreaID;
			$MUrl['SeatID']=$SeatID;
			$MUrl['Tnum']=$tnum;
			$MUrl['Fid']=$member;
			$MUrl['PayStatus']=$pay_status;
			$MUrl['TicketID']=$tid;
			$MUrl['TouristName']=$ordername;
			$MUrl['TouristTel']=$ordertel;
			$MUrl['PlayDate']=$playtime;
			$MUrl['IdCard']=$personID;
			$Mpath_Before=$Mpath."?".http_build_query($MUrl);
			$rMret=file_get_contents($Mpath_Before);
			$this->logrec($rMret);
			if ($rMret) {
				$arrMret=explode('|',$rMret);
				$rSignal=$arrMret[0];
				if ($rSignal!=200) return errXML($this->err5001);
				else 
				{
					$PerInfo=$arrMret[1];
					if ($arrMret[2]) {
						$Mseries[4]=$arrMret[2];
						$Mseries[5]=$arrMret[3];
						$Mseries[6]=$arrMret[1];
						$series=serialize($Mseries);
					}
					if ($arrMret[4]) $VTcode=$arrMret[4];
					if ($arrMret[5]) $VTordernum=$arrMret[5];
				}
			}
			else return errXML($this->err5001);
		}
		
		$chk_code_i=0;
		$remsg=($smsSend==0)?1:0;
		do {
			$str="insert ".$this->t7." set member='$member',ordernum='$ordern',certnum='$mid',remotenum='$remotenum',lid='$lid',tid='$tid',aid='$aid',begintime='$begintime',endtime='$endtime',tnum='$tnum',tprice='$tprice',ordername='$ordername',ordertel='$ordertel',contacttel='$contactTEL',ordertime=now(),salerid='$salerid',paymode='$paymode',ordermode='$ordermode',totalmoney=$totalmoney,personid='$personID',code='$cert'";
			if ($dcodeURL) $str.=",callback=1";
			$str.=",unionCheck=$unionCheck,remsg=$remsg";
			$tquery=$GLOBALS['le']->query_e($str);
			if ($tquery==='MYEALL') {
				$str="select id from ".$this->t7." where status<>3 and remotenum='$remotenum' and member='$member' order by id desc limit 1";
				$GLOBALS['le']->query($str);
				if ($GLOBALS['le']->fetch_assoc()) {
					return errXML($this->err5);
					break;
				}
				if ($chk_code_i>50) {
					return errXML($this->err20);
					break;
				}				
				$ordern++;
				$chk_code_i++;
				continue;
			}
			else break;
		}while($chk_code_i<60);
		
		//终端处理
		//$pay_mode=1;
		$u_price=$this->get_Dynamic_Price_Merge($pid, $begintime, 1, '', '', 1);
		
		if ($terminal_type==0) {
			$pstr="select id from merch_info where compn_id='".$salerid."'";
			$lee->pgquery($pstr);
			$lee->pgFetchAssoc();
			$merch_id=$lee->f('id');
			if (!$merch_id) return errXML($this->err18);
	
			$pstr="select branch_id from term_info where id='".$merch_id."'";
			$lee->pgquery($pstr);
			$lee->pgFetchAssoc();
			$branch_id=$lee->f('branch_id');
			if (!$branch_id) return errXML($this->err18);
	
			$asrc=array();
			$asrc['id']=$ordern;
			$asrc['src_order']=$branch_id;
			$asrc['src_merch']=$merch_id;
			$asrc['dst_merch']=$salerid;
			$asrc['client_name']="'".$ordername."'";
			$asrc['phone_no']="'".$ordertel."'";
			$asrc['order_state']=0;
			//$asrc['total_price']=$totalmoney;
			$asrc['total_price']=isset($u_price)?$u_price*$tnum:$totalmoney;
			$asrc['pay_mode']=$pay_status;
			$asrc['prepays']=0;
			$asrc['vouch_code']="'".$salerid.$cert."'";
			$asrc['order_time']="now()";
			// if ($delaydays==0) $asrc['begin_time']="'".$begintime."'";
			// else $asrc['begin_time']="now()";
			$asrc['begin_time']="'".$begintime."'";
			$asrc['end_time']="'".$endtime."'";
			$asrc['ins_time']="now()";
			$asrc['upd_time']="now()";
			$asrc['tid']=$tid;
			$asrc['tprice']=$tprice;
			$asrc['tnum']=$tnum;
			$asrc['linkid']=$concatID;
			$asrc['linkto']=$pCode;
			$asrc['pid']=$pid;
			$asrc['person_id']="'".$personid."'";
			if ($v_time_limit) $asrc['v_time_limit']="'".$v_time_limit."'";
			$pstr="insert into order_info (".make_sql($asrc).") values (".make_sql($asrc,2).")";
			$lee->pgquery($pstr);
	
			$as2=array();
			$as2['order_id']=$ordern;
			$as2['wares_id']=$tid;
			$as2['quantity']=$tnum;
			$as2['wares_state']=0;
			$as2['begin_time']="now()";
			$as2['end_time']="'".$endtime."'";
			$as2['accept_time']="now()";
			$as2['verify_time']="now()";
			$as2['ins_time']="now()";
			$as2['upd_time']="now()";
			//$as2['tw_price']=$tprice;
			$as2['tw_price']=isset($u_price)?$u_price:$tprice;
			$as2['pid']=$pid;
			$as2['seller_name']="'".$dname."'";
			//$as2['pid']=$tprice*100;
	
			$pstr="insert into order_wares (".make_sql($as2).") values (".make_sql($as2,2).")";
			$lee->pgquery($pstr);
	
			$pstr="select id from wares_info where pid='".$pid."'";
			$lee->pgquery($pstr);
			$lee->pgFetchAssoc();
			$pg_tid=$lee->f('id');
	
			$as3=array();
			$as3['id']=$tid;
			$as3['merch_id']=$salerid;
			$as3['wares_type']=1;
			$as3['wares_name']="'".$ttitle."'";
			$as3['wares_desc']="''";
			if ($order_limit) $as3['wares_desc']="'".$order_limit."'";
			$as3['wares_unit']="''";
			$as3['wares_price']=isset($u_price)?$u_price:$tprice;
			$as3['ins_time']="now()";
			$as3['upd_time']="now()";
			$as3['pid']=$pid;
	
	
			if ($pg_tid) {
			$pstr="update wares_info set ";
			foreach ($as3 as $key=>$val) {
			if ($key!="id"){
				$pstr.=$key."=".$val;
				if ($key!="pid") $pstr.=",";
			}
			}
			$pstr.=" where pid='$pid'";
	
			}else{
			$pstr="insert into wares_info (".make_sql($as3).") values (".make_sql($as3,2).")";
			}
			$lee->pgquery($pstr);
		}

		//处理资金账户
		if ($paymode==0){
			$dismoney=$totalmoney;
			$str="update pft_member_money set amoney=amoney-$dismoney where fid=$member";
			$GLOBALS['le']->query($str);
			//资金流向记录
			$dmoney=$dismoney;
			$lmoney=$amoney-$dmoney;
			$str="insert pft_member_journal set fid=$member,dmoney=$dmoney,lmoney=$lmoney,orderid='$ordern',daction=1,rectime=now(),dtype=0,ptype=0";
			$GLOBALS['le']->query($str);			
		}elseif($paymode==2){
		//处理供应商可用余额
			$dscore=$totalmoney;
			$str="update pft_member_credit set kmoney=kmoney-$dscore where fid=$member and aid=$aid limit 1";
			$GLOBALS['le']->query($str);
			//资金流向记录
			$dmoney=$dscore;
			$lmoney=$kmoney-$dmoney;
			$str="insert pft_member_journal set fid=$member,dmoney=$dmoney,lmoney=$lmoney,aid=$aid,orderid='$ordern',daction=1,rectime=now(),dtype=0,ptype=2";
			$GLOBALS['le']->query($str);	
		}

		//余额清分
		if ($paymode==0){
			//取出几种费用
/* 			$str="select fee_platform,fee_bank,fee_sms from pft_member where id=$aid limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			//$fee_platform=$GLOBALS['le']->f('fee_platform');
			$fee_bank=$GLOBALS['le']->f('fee_bank');
			//$fee_sms=$GLOBALS['le']->f('fee_sms');
			
			$fees=floor($fee_bank*$totalmoney/1000); */
						
			//资金清分到供应商
			//$aid_money=$totalmoney-$fees;
			$aid_money=$totalmoney;
			$str="update pft_member_money set amoney=amoney+$aid_money where fid=$aid";
			$GLOBALS['le']->query($str);
			$str="select amoney from pft_member_money where fid=$aid";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$l_aid_money=$GLOBALS['le']->f('amoney');
						
			$str="insert pft_member_journal set fid=$aid,dmoney=$aid_money,lmoney=$l_aid_money,orderid='$ordern',daction=0,rectime=now(),dtype=0,ptype=0";
			$GLOBALS['le']->query($str);			
			
			
/* 			//资金清分到平台
			$str="update pft_member_money set amoney=amoney+$fees where fid=1";
			$GLOBALS['le']->query($str);
			$str="select amoney from pft_member_money where fid=1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$l_admin_money=$GLOBALS['le']->f('amoney');
						
			$str="insert pft_member_journal set fid=1,dmoney=$fees,lmoney=$l_admin_money,orderid='$ordern',daction=0,rectime=now(),dtype=9,ptype=0";
			$GLOBALS['le']->query($str); */
		
		}
/* 			//供货价
			$f_price=$this->get_Dynamic_Price_Merge($pid, $begintime, 1);
			//零售价
			$u_price=$this->get_Dynamic_Price_Merge($pid, $begintime, 1, '', '', 1); */

		//确认订单状态更新
		$str="select d_status from uu_products where id='".$pid."'";
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$d_status=$GLOBALS['le']->f('d_status');
		$d_stat=(!$d_status)?0:1;
		$str="insert into uu_order_addon set orderid='$ordern',dstatus=$d_stat,ifpack=$pCode";
		// if (isset($VTcode) && $VTcode) $str.=",vcode='$VTcode',tordernum='$VTordernum'";
		if (isset($VTcode) && $VTcode) $str.=",vcode='$VTcode'";
		if (isset($VTordernum) && $VTordernum) $str.=",tordernum='$VTordernum'";
        $GLOBALS['le']->query($str);
		


		//多级供应资金处理
		if ($a_a_money){
			if ($paymode!=1){
				foreach ($a_a_money as $k=>$v){
					$fh=$v[2]?'+':'-';
					$daction=$v[2]?0:1;
					if ($v[1]==0) {
						//处理退信用额度
						$str="update pft_member_credit set kmoney=kmoney$fh".$v[3]." where fid='".$v[0]."' and aid='".$v[4]."' limit 1";
						$GLOBALS['le']->query($str);				
						
						$str="select kmoney from pft_member_credit where fid='".$v[0]."' and aid='".$v[4]."' limit 1";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('kmoney');
						$str="insert pft_member_journal set fid='".$v[0]."',dmoney=".$v[3].",lmoney=$l_money,orderid='$ordern',daction=$daction,aid='".$v[4]."',rectime=now(),dtype=0,ptype=2";
						$GLOBALS['le']->query($str);
					
					}elseif ($v[1]==1){
						//处理资金账户
						$str="update pft_member_money set amoney=amoney$fh".$v[3]." where fid='".$v[0]."' limit 1";
						$GLOBALS['le']->query($str);				
						
						$str="select amoney from pft_member_money where fid='".$v[0]."'";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('amoney');
						$str="insert pft_member_journal set fid='".$v[0]."',dmoney=".$v[3].",lmoney=$l_money,orderid='$ordern',daction=$daction,rectime=now(),dtype=0,ptype=0";
						$GLOBALS['le']->query($str);		
					}		
				}
			}
			$aids_money=serialize($a_a_money);
		}
		
		//多级供应价格
		if ($a_aids_price) $aids_price=implode(',',$a_aids_price);
		else $aids_price='';
		if (!isset($aids_money)) $aids_money='';

		//$str="insert uu_order_fx_details set assembly='$assembly',series='$series',orderid='$ordern',pay_status='$pay_status'";
		$str="insert uu_order_fx_details set assembly='$assembly',series='$series',orderid='$ordern',pay_status='$pay_status',aids_money='$aids_money',aids='$aids',aids_price='$aids_price'";
		$GLOBALS['le']->query($str);

/* 		if (isset($remote_ordern) && ($sync_status==1 || $sync_status==2)){
			$urlStr='http://open.16u.com/PFTtoUU_order_sync_INS.php?';
			$arrUrl=array();
			$arrUrl['ordern_uu']=$remote_ordern;
			$arrUrl['ordern_pft']=$ordern;
			$urlStr.=http_build_query($arrUrl);
			$res_ret=file_get_contents($urlStr);
			$remote_orderid=($res_ret==100)?$remote_ordern:'error'.$remote_ordern;
			$str="update uu_order_sync_status set dstatus=1,remote_orderid='$remote_orderid',fromt='UU',sync_time=now() where orderid='$ordern' and dstatus=0 limit 1";
			$GLOBALS['le']->query($str);			
		} */

		//检查凭证码是否重复
		if ($sync_status!=1 && $sync_status!=2) {
			$str="select id from uu_ss_order where lid='$lid' and code='$cert' and status=0 and ordernum<>'$ordern' limit 1";
			if ($pCode==1) $str="select s.id from uu_ss_order s left join uu_order_addon a on s.ordernum=a.orderid where a.ifpack=1 and s.code='$cert' and status=0 and s.ordernum<>'$ordern' limit 1";
			$GLOBALS['le']->query($str);
			if ($GLOBALS['le']->fetch_assoc()) {
				$chk_code_i=0;
				do {
					//更新验证码
					$mid=$mid+rand(0,10);
					if ($mid>=$ch3 && $pCode==1) $mid=$ch2;
					elseif ($mid>=$ch1_s) $mid=$ch1;
					$TsalerID=($pCode==1)?'987654':$salerid;
					$cert=hashstr((string)$mid,$TsalerID);
					//更新终端			
					$str="update uu_ss_order set certnum='$mid',code='$cert' where ordernum='$ordern' limit 1";
					$GLOBALS['le']->query($str);					
					$pstr="update order_info set vouch_code='".$salerid.$cert."' where id='$ordern'";
					if ($terminal_type==0) $lee->pgquery($pstr);

					$str="select id from uu_ss_order where lid='$lid' and code='$cert' and status=0 and ordernum<>'$ordern' limit 1";
					if ($pCode==1) $str="select s.id from uu_ss_order s left join uu_order_addon a on s.ordernum=a.orderid where a.ifpack=1 and s.code='$cert' and status=0 and s.ordernum<>'$ordern' limit 1";
					$GLOBALS['le']->query($str);
					if ($GLOBALS['le']->fetch_assoc()) {
						$chk_code_i++;
						if ($chk_code_i>50) {
							return errXML($this->err201);
							break;
						}	
						continue;					
					}
					else break;					
				}while($chk_code_i<60);
			}
		}

		if ($Mdetails==1) {
			//下单成功通知
			$MUrl['Ordern']=$ordern;	
			$MUrl['Action']='Relation';	
			$Mpath_After=$Mpath."?".http_build_query($MUrl);
			@file_get_contents($Mpath_After);
		}
		@file_get_contents("http://10.160.4.140/serv/order_split_T.php?ordern=$ordern");
		if (isset($VTcode) && $VTcode) $cert=$VTcode;
		
		$a5=array();
        if ($smsSend!=1) {
			require_once("../tel/tel.php");
			require_once("../tel/order1.php");
	
/* 			if ($num>0){
				$str="update uu_ss_order set remsg=1 where ordernum='$ordern'";
				$GLOBALS['le']->query($str);
			}else{
				$str="update uu_ss_order set smserror='$num' where ordernum='$ordern'";
				$GLOBALS['le']->query($str);
			// return errXML($this->err1074);
			} */
			
			$a51=array('ordernum'=>$ordern,'remotenum'=>$remotenum);
			$a5[]=$a51;
			return toXML($this->lang,$a5);
		}else{
			$code_url="http://12301.cc/".$this->sms_qrcode_url($ordern);
			// if ($pCode>100000) $certString=$s_salerid.$s_certnum;
			// else $certString=$salerid.$mid;
			$img_url="http://121.199.25.173/open/qr?".$this->Make_Qrcode($cert);
			
			$a51=array('ordernum'=>$ordern,'remotenum'=>$remotenum,'code'=>$cert,'qrcodeURL'=>$code_url,'qrcodeIMG'=>$img_url);
			$a5[]=$a51;
			return toXML($this->lang,$a5);
		}

		}else{
		return errXML($this->err1);
		}

    }

//（票付通外部）订单统一查询搜索接口（景区编号,分销商ID（逗号分隔）,供应商ID（逗号分隔）,门票ID,景区模糊标题,门票模糊标题,下单时间开始,下单时间结束,预计游玩时间开始,预计游玩时间结束,订单完成时间开始,订单完成时间结束,票付通订单号,商家订单号,取票人姓名,取票人手机,状态（0未使用|1已使用|2已过期|3被取消|4凭证码被替代）,支付状态（1已支付|2未支付）,排序(1下单时间|2游玩时间|3实际使用时间|4商户ID|5景区标题|6取消时间), 升序或降序（0升序|1降序), 记录起始指针, 返回条数, 返回类型（0详细1返回总数2逗号隔开字符串#订单数,票数,总数）, 联系人手机, 支付（为空不做筛选0帐号余额支付1支付宝2使用供应商可用金额支付),产品类型（A景区B线路C酒店F套票）,订单类型int1分销订单2供应订单, 关联订单(0显示所有订单 1显示关联订单【订单号不能为空】）,套票（默认显示主票、1显示包含子票、2仅包含子票）, 凭证码, 身份证
	public function Order_Globle_Search($ac, $pw, $sid, $mid, $aid, $tid, $ltitle, $ttitle, $btime1, $etime1, $btime2, $etime2, $btime3, $etime3, $ordernum, $remotenum, $oname, $otel, $status='', $pays='', $orderby, $sort, $rstart, $n=40, $c=0, $contactTEL='', $payinfo='', $p_type='', $ordertype=1, $concat='', $ifpack='', $code=NULL, $personid=NULL, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		
		$this->logrec("Order_Globle_Search#ac:$ac, pw:$pw, sid:$sid, mid:$mid, aid:$aid, tid:$tid, ltitle:$ltitle, ttitle:$ttitle, btime1:$btime1, etime1:$etime1, btime2:$btime2, etime2:$etime2, btime3:$btime3, etime3:$etime3, ordernum:$ordernum, remotenum:$remotenum, oname:$oname, otel:$otel, status:$status, pays:$pays, orderby:$orderby, sort:$sort, rstart:$rstart, n:$n, c:$c, ordermode:$ordermode, payinfo:$payinfo, p_type:$p_type, ordertype:$ordertype, concat:$concat, ifpack:$ifpack, code:$code, personid:$personid, m:$m");
		
		if ($c==='') $c=0;
		$orderby=($orderby==='')?1:$orderby;
		$sort=($sort==='')?0:$sort;
		if ($remotenum || $ordernum) $sort=1;
		$rstart=($rstart==='')?0:$rstart;
		$n=($n==='')?40:$n;
		// $concat=($concat==='')?0:$concat;
		$ifpack=($ifpack==='')?0:$ifpack;
		if ($ordertype!=2) $ordertype=1;
		if ($code && !$sid) return $this->err4001;
		if ($personid && !$sid) return $this->err4001;
		if ($this->ac_qx==1 && !$sid) return $this->err4001;
		//$sid="";
		$mid="";
		$aid="";
		// $tid="";
		$ltitle="";
		$ttitle="";
		// $btime1="";
		// $etime1="";
		// $btime2="";
		// $etime2="";
		// $btime3="";
		// $etime3="";
		// $oname="";
		// $otel="";
		// $status="";
		// $pays="";
		// $contactTEL="";
		// $payinfo="";
		// $p_type="";

        $ordernum=trim($ordernum);
		//身份识别0供应商1分销商
		$str="select id,dtype from pft_member where account='$ac'";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$dtype=$GLOBALS['le']->f('dtype');
		$id=$GLOBALS['le']->f('id');
		
		if ($this->ac_qx==1) {
			$str="select id from uu_land where salerid='$sid' and apply_did='$id' limit 1";
			$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return $this->err4002;		
		}
		
		//分销商只能查询自己的订单

		if ($dtype!=0 && $dtype!=1) return errXML($this->err24);
		if ($ordertype==2) $aid=($this->ac_qx==1)?'':$id;
		elseif ($ordertype==1) $mid=($this->ac_qx==1)?'':$id;
		
		$str="";

		//查询订单SQL构造

		$str.="select ";

		if ($c==0) {
			$str.="d.account,d.dname,s.ordernum,s.remotenum,s.certnum,s.lid,s.tid,l.title as ltitle,t.title as ttitle,t.getaddr,s.begintime,s.ordertime,s.endtime,s.tnum,s.tprice,s.ordername,s.ordertel,s.status,s.salerid,s.dtime,s.remsg,fd.pay_status as paystatus,s.totalmoney,s.contacttel,s.smserror,s.paymode as pmode,s.ordermode,s.ctime,t.pid,fd.origin,fd.memo,l.p_type,r.dhour,t.status as cstatus,r.mdays,r.mhour,r.startplace,r.endplace,r.rdays,n.dstatus,n.confirm_time,n.confirm_op,n.ifprint,fd.series,fd.assembly,s.aid,fd.concat_id,n.ifpack,a.lprice,t.tprice as Mprice,fd.aids";
			if ($this->ac_qx==1) $str.=",s.code,s.personid";
		}

		//统计2
		else $str.="s.tnum,s.tprice,s.totalmoney,s.onsale";		

		$str.=" from uu_ss_order s left join uu_land l on s.lid=l.id left join uu_jq_ticket t on s.tid=t.id left join pft_member d on s.member=d.id left join uu_land_f r on s.tid=r.tid left join uu_order_fx_details fd on s.ordernum=fd.orderid left join uu_order_addon n on s.ordernum=n.orderid left join uu_order_apply_info a on s.ordernum=a.orderid";
		if ($ordernum && $concat!=1 ) {
			$str.=" where s.ordernum='".$ordernum."'";// or n.ifpack='".htmlspecialchars($ordernum)."')";
			//if ($ifpack===0) $str.=" and (n.ifpack<10000 or n.ifpack is NULL)";
			//elseif ($ifpack===2) $str.=" and (n.ifpack<>1 or n.ifpack is NULL)";
			if ($mid) $str.=" and d.id='$mid'";
			if ($aid) $str.=" and s.aid='$aid'";
			if ($sid) $str.=" and s.salerid='$sid'";
			// if ($mid || $aid) $str.=$this->get_ids_match($mid, $aid);
		}elseif ($ordernum && $concat==1) {
			$str.=" where fd.concat_id='".$ordernum."'";
			if ($mid) $str.=" and d.id='$mid'";
			if ($aid) $str.=" and s.aid='$aid'";
			if ($sid) $str.=" and s.salerid='$sid'";
			// $str.=" group by s.ordernum ";
		}else{
			$str.=" where 1=1";
			if ($sid) $str.=" and s.salerid='$sid'";
			//if (strpos($mid,',')!==false) $str.=" and d.id in ($mid)";
			//elseif ($mid) $str.=" and d.id='$mid'";
			// if ($mid || $aid) $str.=$this->get_ids_match($mid, $aid);
			if ($mid) $str.=" and d.id='$mid'";
			if ($aid) $str.=" and s.aid='$aid'";
			if ($lid) $str.=" and s.lid='$lid'";
			else $str.=" and s.lid>0";
			if ($tid) $str.=" and s.tid='$tid'";
			if ($ltitle) $str.=" and instr(l.title,'".$ltitle."')>0";
			if ($ttitle) $str.=" and instr(t.title,'".$ttitle."')>0";
			if ($btime1) $str.=" and s.ordertime>='$btime1'";
			if ($etime1) $str.=" and s.ordertime<='$etime1'";
			if ($btime2) $str.=" and s.begintime>='$btime2'";
			if ($etime2) $str.=" and s.begintime<='$etime2'";
			if ($btime3) $str.=" and s.dtime>='$btime3'";
			if ($etime3) $str.=" and s.dtime<='$etime3'";
			if ($oname) $str.=" and instr(s.ordername,'".$oname."')>0";
			if ($otel) $str.=" and s.ordertel='".$otel."'";
			if ($contactTEL) $str.=" and s.contacttel='".$contactTEL."'";
			//if ($fromt) $str.=" and d.oid='$fromt'";
			if ($remotenum) $str.=" and s.remotenum='$remotenum'";
			if ($origin) $str.=" and fd.origin='$origin'";
			if ($p_type) $str.=" and l.p_type='$p_type'";
			if ($this->ac_qx==1 && $code) $str.=" and s.code='$code'";
			if ($this->ac_qx==1 && $personid) $str.=" and s.personid='$personid'";
			//if (strpos($aid,',')!==false) $str.=" and s.aid in ($aid)";
			//elseif ($aid) $str.=" and s.aid='$aid'";
			//if ($aid!=='') $str.=" and s.aid='$aid'";
			if ($concat==1) $str.=" and (fd.concat_id='' or fd.concat_id='main')";
			//if ($ifpack===0) $str.=" and (n.ifpack<10000 or n.ifpack is NULL)";
			//elseif ($ifpack===2) $str.=" and (n.ifpack<>1 or n.ifpack is NULL)";
			if ($status!=='') {
				if ($st=$this->stt($status, "s.status")) {
				$str.=$st;
				}else{
				return $this->err21;
				}
			}
	
			if ($pays!=='') {
				if ($st=$this->stt($pays, "fd.pay_status")) {
				$str.=$st;
				}else{
				return $this->err21;
				}
			}
	
			if ($payinfo!=='') $str.=" and s.paymode=$payinfo";
		}


		if ($c==0){
		$asc=$sort?"desc":"asc";
		  switch ($orderby) {
			case 1: $str.=" order by s.id ".$asc;break;
			case 2: $str.=" order by s.begintime ".$asc;break;
			case 3: $str.=" order by s.dtime ".$asc;break;
			case 4: $str.=" order by s.salerid ".$asc;break;
			case 5: $str.=" order by s.ltitle ".$asc;break;
			case 6: $str.=" order by s.ctime ".$asc;break;
			default:$str.=" order by s.id ".$asc;break;
		  }
		$str.=" limit $rstart,$n";
		}

		$a1=array();
		if (!$GLOBALS['le']->query($str)) return $this->err3;
		while ($row=$GLOBALS['le']->fetch_assoc()) {
			if ($this->ac_qx==1) {			
				$row['qrcode']=$this->Make_Qrcode($row['code']);
			}
			$a1[]=$row;
		}

		if ($c==1) {
			$ca1=count($a1);
			$a2[]=array('count'=>$ca1);
			return toXML($this->lang,$a2);
		}
		if ($c==2) {
			$sum1=count($a1);//订单数
			$sum2=0;//票数
			$sum3=0;//总额
		    foreach ($a1 as $v){
			  $sum2+=$v[tnum];
			  if ($v['onsale']==1) $sum3+=$v[totalmoney];
			  else $sum3+=$v[tprice]*$v[tnum];
			}
			$ca2=$sum1.','.$sum2.','.$sum3;
			$a3[]=array('countstring'=>$ca2);
			return toXML($this->lang,$a3);
		}

		return toXML($this->lang,$a1);
		//return $str;

		}else{
		return errXML($this->err1);
		}

    }

//订单短信发送、重发接口 (票付通订单号)
	public function reSend_SMS_Global_PL($ac, $pw, $ordern, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("reSend_SMS_Global_PL#ac:$ac, pw:$pw, ordern:$ordern, m:$m");
		$table=$this->t7;
		//$playtime=($ordern>$this->orderCounter)?'playtime as ptime':'begintime as ptime';
		$str="select id from pft_member where account='$ac' and status=0";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$aid1=$GLOBALS['le']->f('id');	
		
		$str="select * from $table where ordernum='".$ordern."' limit 1";
        $GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err5);

		$lid=$GLOBALS['le']->f('lid');
		$tid=$GLOBALS['le']->f('tid');
		$remsg=$GLOBALS['le']->f('remsg');
		$certnum=$GLOBALS['le']->f('certnum');
		$salerid=$GLOBALS['le']->f('salerid');
		$ordertel=$GLOBALS['le']->f('ordertel');
		$begintime=$GLOBALS['le']->f('begintime');
		$endtime=$GLOBALS['le']->f('endtime');
		$tnum=$GLOBALS['le']->f('tnum');
		$member=$GLOBALS['le']->f('member');
		$aid=$GLOBALS['le']->f('aid');
		if (!$aid) return errXML($this->err1073);
		$cert=$GLOBALS['le']->f('code');
		
		if ($aid!=$aid1 && $member!=$aid1) return errXML($this->err24);

		$str="select orderid from uu_order_fx_details where concat_id='$ordern'";
        $GLOBALS['le']->query($str);
		$arr1=array();
		while($row=$GLOBALS['le']->fetch_assoc()) $arr1[]=$row;

		if ($remsg>3) return errXML($this->err16);
		//构造凭证号
		// $cert=hashstr((string)$certnum, (string)$salerid);
/*
		$str="select oid,passport,smstype from uu_distributor where id='".$member."'";
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$oid=$GLOBALS['le']->f('oid');
		$passport=$GLOBALS['le']->f('passport');
		$smstype=$GLOBALS['le']->f('smstype');

		$str="select oname,fax from uu_org where id='".$oid."'";
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$oname=$GLOBALS['le']->f('oname');
		$c_tel=$GLOBALS['le']->f('fax');
*/
 	    require_once("../tel/tel.php");
		require_once("../tel/order1.php");
		

		if ($num>0) {
			$str="update $table set remsg=remsg+1 where ordernum='$ordern' limit 1";
			$GLOBALS['le']->query($str);
			$a5=array();
			$a5[]=array('done'=>100);
			return toXML($this->lang,$a5);
		}else{
			$str="update $table set smserror='$num' where ordernum='$ordern'";
			$GLOBALS['le']->query($str);
			return errXML($this->err1074);
		}

		}else{
			return errXML($this->err1);
		}

    }

//（票付通）修改、取消订单多功能退款版 参数：订单号，数量（0为取消订单|-1不做修改），修改取票人手机）
	public function Order_Change_Pro($ac, $pw, $ordern, $num=-1, $ordertel=NULL, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("reSend_SMS_Global_PL#ac:$ac, pw:$pw, ordern:$ordern, num:$num, ordertel:$ordertel, m:$m");
	
		
		if (is_numeric($ordern)===false || is_numeric($num)===false) return errXML($this->err11);
		if ($num==-1 && !$ordertel) return errXML($this->err45);
		
		$str="select id from pft_member where account='$ac' and status=0";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$member=$GLOBALS['le']->f('id');	
		
		$table=$this->t7;
		$c_op=$member;
		//判断是否有修改的权限
		// $str="select * from $table where ordernum='$ordern' and member='$member' limit 1";
		$str="select s.*,n.ifpack from uu_ss_order s left join uu_order_addon n on s.ordernum=n.orderid where s.ordernum='$ordern' and member='$member' limit 1";
		$GLOBALS['le']->query($str);
		$r=$GLOBALS['le']->fetch_assoc();
		if (!$r) return errXML($this->err23);
		$linkto=$r['ifpack'];
		if (($r['status']==3 || $r['status']==6) && $num==0) {
			$a5=array();
			$a5[]=array('done'=>100,'order'=>$ordern,'ctime'=>$r['ctime']);
			return toXML($this->lang,$a5);
		}
		// if ($r['status']==2 && $num!=0) return errXML($this->err1076);
		if ($r['status']!=0) return errXML($this->err1077);

		$str="select Mdetails,Mpath,buy_limit_up,buy_limit_low from uu_jq_ticket where id=".$r['tid']." limit 1";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$Mdetails=$GLOBALS['le']->f('Mdetails');		
		$Mpath=$GLOBALS['le']->f('Mpath');
		$buy_limit_up=$GLOBALS['le']->f('buy_limit_up');
		$buy_limit_low=$GLOBALS['le']->f('buy_limit_low');
		
		if ($num>$buy_limit_up && $buy_limit_up!=0 && $num>0) return errXML($this->err1091);
		if ($num<$buy_limit_low && $buy_limit_low!=0 && $num>0) return errXML($this->err1091);
		
		if ($Mdetails==1) {
			$str="select series from uu_order_fx_details where orderid='$ordern' limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$series=$GLOBALS['le']->f('series');		
		
			$Mseries=unserialize($series);
			$VenueID=$Mseries[0]?$Mseries[0]:'';
			$RoundID=$Mseries[1]?$Mseries[1]:'';
			$AreaID=$Mseries[2]?$Mseries[2]:'';
			$SeatID=$Mseries[3]?$Mseries[3]:'';
			$MUrl=array();
			$MUrl['VenueID']=$VenueID;
			$MUrl['RoundID']=$RoundID;
			$MUrl['AreaID']=$AreaID;
			$MUrl['SeatID']=$SeatID;
			$MUrl['Tnum']=$num;
			$MUrl['Fid']=$member;
			$MUrl['Ordern']=$ordern;
			$MUrl['Action']='MOD';
			$Mpath_Mod_Before=$Mpath."?".http_build_query($MUrl);
			$rMret=file_get_contents($Mpath_Mod_Before);
			$this->logrec('MOD'.$rMret);
			if ($rMret) {
				$arrMret=explode('|',$rMret);
				$rSignal=$arrMret[0];
				if ($rSignal!=200) return errXML($this->err5002);
				else 
				{
					$PerInfo=$arrMret[1];
					if ($arrMret[2]) {
						$Mseries[4]=$arrMret[2];
						$Mseries[5]=$arrMret[3];
						$Mseries[6]=$arrMret[1];
						$series=serialize($Mseries);
						$str="update uu_order_fx_details set series='$series' where orderid='$ordern' limit 1";
						$GLOBALS['le']->query($str);						
					}
				}
			}
			else return errXML($this->err5002);			
		}
		//闸机撤改7517待开放
		$str="select apply_did,terminal_type from uu_land where id=".$r['lid']." limit 1";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$l_apply_did=$GLOBALS['le']->f('apply_did');
		$terminal_type=$GLOBALS['le']->f('terminal_type');
		
		if ($terminal_type==0) { 
			require_once("../conf/pg.le.je");
			$lee = new pgconn();
			$lee->getConn();
			$pstr="select order_state,linkto from order_info where id='".$ordern."'";
			$lee->pgquery($pstr);
			$lee->pgFetchAssoc();
			$order_state=$lee->f('order_state');
			$linkto=$lee->f('linkto');
			if ($order_state!=0 && $order_state!=4 && $order_state!=2) return errXML($this->err1077);
		}
		
/* 		if ($num!=-1 && $l_apply_did==7517) {
			$m_url="http://max.12301.cc/gate_machine_order_cancel.php?ordern=$ordern";
			if ($num!=0) $m_url.="&tnum=$num";
			$m_url.="&price=".$r['tprice'];
			$xx=@file_get_contents($m_url);
			if ($xx!=100) return errXML($this->err18);		
		}	 */
		
		if ($linkto>=1) {
			//套票子票不能单独取消
			if ($linkto>1) return errXML($this->err2022);
			if ($linkto==1) {
				$res_coupon=file_get_contents("http://open.12301.cc/pft_coupon_modify_sys.php?ordern=".$ordern."&pnum=".$r['tnum']."&anum=".$num);
				if ($res_coupon==101) return errXML($this->err2023);
			}
		}
		$totalmoney=$r['tprice']*$r['tnum'];
		//构造SQL
		if ($num<=$r['tnum']) {
			$totalmoney1=$r['tprice']*$num;
			if ($num!=0){
			  //更新订单
			  //totalmoney不相等退出
/* 			  if ($totalmoney!=$totalmoney1) return $this->err44;
			  $totalmoney=$r['tprice']*$num; */
		      $str="update ".$table." set id=id ";
		      if ($num!=-1) $str.=",tnum='$num',totalmoney='$totalmoney1'";
			  if ($ordertel) $str.=",ordertel='$ordertel'";
			  $str.=" where status=0 and ordernum='$ordern' limit 1";
			  $GLOBALS['le']->query($str);
			  
			  $pstr="update order_info set id=id ";
			  if ($num!=-1) $pstr.=",tnum=$num,total_price=$totalmoney1";
			  if ($ordertel) $pstr.=",phone_no='$ordertel'";

			  $pstr.=" where id='".$ordern."'";
			  if ($terminal_type==0) $lee->pgquery($pstr);
			  
			  if ($num!=-1){
				$pstr="update order_wares set quantity=$num where order_id='".$ordern."'";
				if ($terminal_type==0) $lee->pgquery($pstr);
			  }

 			  $str="update uu_order_addon set dstatus=5,confirm_time=now(),confirm_op='$c_op' where orderid='".$ordern."'";
			  $GLOBALS['le']->query($str); 
			}elseif($num==0){
			  //取消订单
			  $str="update ".$table." set status='3',ctime=now() where ordernum='$ordern' limit 1";
			  if (!$GLOBALS['le']->query($str)) $this->err15;

		      $pstr="update order_info set order_state=2 where id='".$ordern."'";
		      if ($terminal_type==0) $lee->pgquery($pstr);

 			  //更新订单扩展
			  $str="update uu_order_addon set dstatus=4,confirm_time=now(),confirm_op='$c_op' where orderid='".$ordern."'";
			  $GLOBALS['le']->query($str); 
			}
		}else{
			return errXML($this->err1078);
		}

		//虚拟账户退款
		if ($num<$r['tnum'] && $num!=-1) {
			//分销退款
			$totalprice=$r['tprice']*$num;
			//改单不收取手续费
			$lm=$totalmoney-$totalprice;
			if ($num==0) {
				//撤单收取手续费
				$str="select reb,reb_type from uu_jq_ticket where id=".$r['tid'];
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$reb=$GLOBALS['le']->f('reb');
				$reb_type=$GLOBALS['le']->f('reb_type');
				if ($reb){
					//查找是否有原始票数
					$str="select pre_num from pft_order_num_modify where orderid='$ordern' order by id asc limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$pre_num=$GLOBALS['le']->f('pre_num');
					$pre_num=$pre_num?$pre_num:$r['tnum'];
					if ($reb_type==1) $fee_back=$reb*$pre_num;
					else $fee_back=$r['tprice']*$pre_num*$reb/100;
					// $lm=$lm-$fee_back;
				}
			}
			
			$fx_id=$r['member'];
			if (($r['paymode']==0 || $r['paymode']==1) && $lm>0){
				//分销商+
				$str="update pft_member_money set amoney=amoney+$lm where fid='".$r['member']."' limit 1";
				$GLOBALS['le']->query($str);				
				
				$str="select amoney from pft_member_money where fid='".$r['member']."'";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$l_money=$GLOBALS['le']->f('amoney');
				$str="insert pft_member_journal set fid='".$r['member']."',dmoney=$lm,lmoney=$l_money,orderid='$ordern',daction=0,rectime=now(),dtype=1,ptype=0";
				$GLOBALS['le']->query($str);
				
				//供应商-
				$str="update pft_member_money set amoney=amoney-$lm where fid='".$r['aid']."' limit 1";
				$GLOBALS['le']->query($str);				
				
				$str="select amoney from pft_member_money where fid='".$r['aid']."'";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$l_money=$GLOBALS['le']->f('amoney');
				$str="insert pft_member_journal set fid='".$r['aid']."',dmoney=$lm,lmoney=$l_money,orderid='$ordern',daction=1,rectime=now(),dtype=1,ptype=0";
				$GLOBALS['le']->query($str);

				if ($num==0 && $reb){
					//分销商-
					$str="update pft_member_money set amoney=amoney-$fee_back where fid='".$fx_id."' limit 1";
					$GLOBALS['le']->query($str);					
					$str="select amoney from pft_member_money where fid='".$fx_id."' limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$l_money=$GLOBALS['le']->f('amoney');					
					$str="insert pft_member_journal set fid='".$fx_id."',dmoney=$fee_back,lmoney=$l_money,orderid='$ordern',daction=2,rectime=now(),dtype=1,ptype=0";
					$GLOBALS['le']->query($str);
					
					//原始供应商+
					$str="update pft_member_money set amoney=amoney+$fee_back where fid='".$l_apply_did."' limit 1";
					$GLOBALS['le']->query($str);					
					$str="select amoney from pft_member_money where fid='".$l_apply_did."' limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$l_money=$GLOBALS['le']->f('amoney');					
					$str="insert pft_member_journal set fid='".$l_apply_did."',dmoney=$fee_back,lmoney=$l_money,orderid='$ordern',daction=0,rectime=now(),dtype=1,ptype=0";
					$GLOBALS['le']->query($str);
					//分销商-
					// $str="insert pft_member_journal set fid='".$r['member']."',dmoney=$fee_back,lmoney=0,orderid='$ordern',daction=2,rectime=now(),dtype=1,ptype=0";
					// $GLOBALS['le']->query($str);
				}
			}elseif($r['paymode']==2 && $lm>0) {
				//处理退信用额度
				//分销商+
				$str="update pft_member_credit set kmoney=kmoney+$lm where fid='".$r['member']."' and aid='".$r['aid']."' limit 1";
				$GLOBALS['le']->query($str);				
				
				$str="select kmoney from pft_member_credit where fid='".$r['member']."' and aid='".$r['aid']."' limit 1";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$l_money=$GLOBALS['le']->f('kmoney');
				$str="insert pft_member_journal set fid='".$r['member']."',dmoney=$lm,lmoney=$l_money,aid='".$r['aid']."',orderid='$ordern',daction=0,rectime=now(),dtype=1,ptype=2";
				$GLOBALS['le']->query($str);

				if ($num==0 && $reb){
					if ($l_apply_did==$r['aid']){
						//分销商-
						$str="update pft_member_credit set kmoney=kmoney-$fee_back where fid='".$fx_id."' and aid='".$r['aid']."' limit 1";
						$GLOBALS['le']->query($str);
						$str="select kmoney from pft_member_credit where fid='".$fx_id."' and aid='".$r['aid']."' limit 1";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('kmoney');					
						$str="insert pft_member_journal set fid='".$fx_id."',dmoney=$fee_back,lmoney=$l_money,aid=".$r['aid'].",orderid='$ordern',daction=2,rectime=now(),dtype=1,ptype=2";
						$GLOBALS['le']->query($str);
					}else{
						//分销商-
						$str="update pft_member_money set amoney=amoney-$fee_back where fid='".$fx_id."' limit 1";
						$GLOBALS['le']->query($str);					
						$str="select amoney from pft_member_money where fid='".$fx_id."' limit 1";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('amoney');					
						$str="insert pft_member_journal set fid='".$fx_id."',dmoney=$fee_back,lmoney=$l_money,orderid='$ordern',daction=2,rectime=now(),dtype=1,ptype=0";
						$GLOBALS['le']->query($str);
						
						//原始供应商+
						$str="update pft_member_money set amoney=amoney+$fee_back where fid='".$l_apply_did."' limit 1";
						$GLOBALS['le']->query($str);					
						$str="select amoney from pft_member_money where fid='".$l_apply_did."' limit 1";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('amoney');					
						$str="insert pft_member_journal set fid='".$l_apply_did."',dmoney=$fee_back,lmoney=$l_money,orderid='$ordern',daction=0,rectime=now(),dtype=1,ptype=0";
						$GLOBALS['le']->query($str);					
					}
					//分销商-
					// $str="insert pft_member_journal set fid='".$r['member']."',dmoney=$fee_back,lmoney=0,orderid='$ordern',daction=2,rectime=now(),dtype=1,ptype=2";
					// $GLOBALS['le']->query($str);
				}
			}

			$str="select aids_money from uu_order_fx_details where orderid='$ordern' limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$aids_money=$GLOBALS['le']->f('aids_money');
			$num1=$r['tnum'];
			$num2=$num1-$num;
			
			if ($aids_money){
				$a_a_money=unserialize($aids_money);
				foreach ($a_a_money as $k=>$v){
					$fh=$v[2]?'-':'+';
					$daction=$v[2]?1:0;
					$cc_money=$v[3];
					$v[3]=floor($v[3]*$num2/$num1);
					if ($v[1]==0) {
						//处理退信用额度
						$str="update pft_member_credit set kmoney=kmoney$fh".$v[3]." where fid='".$v[0]."' and aid='".$v[4]."' limit 1";
						$GLOBALS['le']->query($str);
						
						$str="select kmoney from pft_member_credit where fid='".$v[0]."' and aid='".$v[4]."' limit 1";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('kmoney');
						$str="insert pft_member_journal set fid='".$v[0]."',dmoney=".$v[3].",lmoney=$l_money,aid='".$v[4]."',orderid='$ordern',daction=$daction,rectime=now(),dtype=0,ptype=2";
						$GLOBALS['le']->query($str);
					
					}elseif ($v[1]==1){
						//处理资金账户
						$str="update pft_member_money set amoney=amoney$fh".$v[3]." where fid='".$v[0]."' limit 1";
						$GLOBALS['le']->query($str);				
						
						$str="select amoney from pft_member_money where fid='".$v[0]."'";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$l_money=$GLOBALS['le']->f('amoney');
						$str="insert pft_member_journal set fid='".$v[0]."',dmoney=".$v[3].",lmoney=$l_money,orderid='$ordern',daction=$daction,rectime=now(),dtype=0,ptype=0";
						$GLOBALS['le']->query($str);		
					}
					
					if ($num>0) $a_a_money[$k][3]=$cc_money-$v[3];
				}
				
				//修改完成更新aids_money
				if ($num>0){
					$aids_money=serialize($a_a_money);
					$str="update uu_order_fx_details set aids_money='$aids_money' where orderid='$ordern' limit 1";
					$GLOBALS['le']->query($str);
				}
			}

		}
		
		//如果是闸机订单必须同步数据
		$str="select id from uu_jq_ticket where id=".$r['tid']." and sourceT=1";
		$GLOBALS['le']->query($str);
		if ($GLOBALS['le']->fetch_assoc()){
			$dtype=($num==0)?0:1;
			$str="insert order_machine_sys set orderid='$ordern',dtype=$dtype,tnum=$num,aid='".$r['aid']."',salerid='".$r['salerid']."',ctime=now()";
			$GLOBALS['le']->query($str);
		}
		if ($Mdetails==1) {
			//修改订单成功通知
			$MUrl['Action']='ModSuccess';
			$Mpath_Mod_After=$Mpath."?".http_build_query($MUrl);
			@file_get_contents($Mpath_Mod_After);
		}
		
		$a5=array();
		$a5[]=array('done'=>100);
		return toXML($this->lang,$a5);
		}else{
		return errXML($this->err1);
		}
    }

//自定义短信发送
	public function Send_SMS_System_Fee($ac, $pw, $tel, $msg, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("Send_SMS_System_Fee#ac:$ac, pw:$pw, tel:$tel, msg:$msg, m:$m");
     	/* if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
			return $this->err31;
		} */
		$str="select id,dtype from pft_member where account='$ac'";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$dtype=$GLOBALS['le']->f('dtype');
		$aid=$GLOBALS['le']->f('id');		
		
		if (!$tel || !$msg || !$aid) return errXML($this->err11);
        require_once("../tel/tel.php");
		$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";

		$msglen=str_len2($msg);
		$x_ac=($msglen>66)?12:10;
      	$url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=".$x_ac."&x_gate_id=300&x_target_no=".$tel."&x_memo=".$msg;
		$num=Get($url);

		if ($num>0) {
			$m=ceil($msglen/66);
			$str="select fee_sms from pft_member where id=$aid limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$fee_sms=$GLOBALS['le']->f('fee_sms');
			$dmoney=$fee_sms*$m;
			
			$str="update pft_member_money set amoney=amoney-$dmoney where fid=$aid";
			$GLOBALS['le']->query($str);		
			
			$str="select amoney from pft_member_money where fid=$aid limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$lmoney=$GLOBALS['le']->f('amoney');
			$str="insert pft_member_journal set fid=$aid,dmoney=$dmoney,lmoney=$lmoney,orderid='$ordern',daction=1,rectime=now(),dtype=8,ptype=0";
			$GLOBALS['le']->query($str);
			
			//平台流水帐
			$str="update pft_member_money set amoney=amoney+$dmoney where fid=1";
			$GLOBALS['le']->query($str);
			$str="select amoney from pft_member_money where fid=1 limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$lmoney=$GLOBALS['le']->f('amoney');		
			$str="insert pft_member_journal set fid=1,dmoney=$dmoney,lmoney=$lmoney,orderid='$ordern',daction=0,rectime=now(),dtype=8,ptype=0";
			$GLOBALS['le']->query($str);			
			
			$a5=array();
			$a5[]=array('done'=>100);
			return toXML($this->lang,$a5);
		}else{
			return errXML($this->err1074);
		}
		}else{
		return errXML($this->err1);
		}
    }

//验证码查看（票付通外部调用）（订单号）
	public function Terminal_Code_Verify($ac, $pw, $ordern, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("Terminal_Code_Verify#ac:$ac, pw:$pw, ordern:$ordern, m:$m");
		if (is_numeric($ordern)===false) return errXML($this->err11);
		$table=$this->t7;
		
		//权限检查
		$str="select id from pft_member where account='$ac' and status=0";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$id=$GLOBALS['le']->f('id');		
		
		$str="select code from ".$table." where member='$id' and ordernum=".$ordern." limit 1";
        $GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$code=$GLOBALS['le']->f('code');
		if (!$code) return errXML($this->err24);

		// $cert=hashstr((string)$certnum, $salerid);

		//rec

		$str="insert code_check_rec set ordernum='$ordern',account='$ac',dtype=1,dtime=now()";
		$GLOBALS['le']->query($str);

		$a5=array();
	    $a5[]=array("code"=>$code);
        return toXML($this->lang,$a5);

		}else{
		return errXML($this->err1);
		}

    }


//资金余额查看 (类型0自己的账户余额1可用供应商余额2供应商开放额度，供应商ID（类型>0时必填））
	public function PFT_Member_Fund($ac, $pw, $dtype=0,$aid=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("PFT_Member_Fund#ac:$ac, pw:$pw, dtype:$dtype, aid:$aid");
		$str="select id from pft_member where account='$ac' and status=0";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err1);
		$id=$GLOBALS['le']->f('id');

		if ($dtype>0 && !$aid) return errXML($this->err3);
		
		$a5=array();
		if ($dtype==0) {
			$str="select amoney from pft_member_money where fid=$id";
			$GLOBALS['le']->query($str);	
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);
		}elseif ($dtype==1){
			$str="select kmoney from pft_member_credit where fid=$id and aid=$aid";
			$GLOBALS['le']->query($str);	
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);		
		}elseif ($dtype==2){
			$str="select basecredit from pft_member_credit where fid=$id and aid=$aid";
			$GLOBALS['le']->query($str);	
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);		
		}
		
		}else{
		return errXML($this->err1);
		}

    }

//会员关系查看（1查看我的分销商2查看我的供应商3查看我的员工）
	public function PFT_Member_Relationship($ac, $pw, $n, $m=NULL) {
		if ($this->authrize($ac, $pw)){
		$this->logrec("PFT_Member_Relationship#ac:$ac, pw:$pw, n:$n, m:$m");
		$str="select id,dtype from pft_member where account='$ac'";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$id=$GLOBALS['le']->f('id');
		$dtype=$GLOBALS['le']->f('dtype');
		
		if ($dtype!=0 && $dtype!=1) errXML($this->err24);

		if (!$n) return errXML($this->err3);
		
		$a5=array();
		if ($n==1) {
			if ($dtype==1) return errXML($this->err24);
			$str="select m.dname,m.address,m.qq,m.cname,m.ctel,m.id as mid from pft_member_relationship r left join pft_member m on r.son_id=m.id where r.parent_id=$id and r.son_id_type=0 and r.ship_type=0 and r.status=0 and m.status=0";
			$GLOBALS['le']->query($str);	
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);
		}elseif ($n==2){
			$str="select m.dname,m.address,m.qq,m.cname,m.ctel,m.id as mid from pft_member_relationship r left join pft_member m on r.parent_id=m.id where r.son_id=$id and r.son_id_type=0 and r.ship_type=0 and r.status=0 and m.status=0";	
			$GLOBALS['le']->query($str);
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);		
		}elseif ($n==3){
			$str="select m.dname,m.address,m.qq,m.cname,m.ctel,m.id as mid from pft_member_relationship r left join pft_member m on r.son_id=m.id where r.parent_id=$id and r.son_id_type=2 and r.ship_type=0 and r.status=0 and m.status=0";
			$GLOBALS['le']->query($str);	
			while ($row=$GLOBALS['le']->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);		
		}
		
		}else{
		return errXML($this->err1);
		}

    }	

//产品抓取通知接口
/* 需要抓取的远端ID号用逗号分隔 
$product_ids:本次需要修改的ID，并且新的会增加到产品库 $autoStatus=1将执行删除记录
*/
	public function Product_Catch_Inform($ac, $pw, $product_ids, $t_get=0, $t_url='', $t_notice_url='', $autoStatus=0) {
		if ($this->authrize($ac, $pw)){
			$this->logrec("Product_Catch_Inform#ac:$ac, pw:$pw, product_ids:$product_ids, t_get:$t_get, t_url:$t_url, t_notice_url:$t_notice_url, autoStatus:$autoStatus");
			//处理产品抓取资料表
			$a5=array();
			if (!$product_ids) return errXML($this->err3000);
			if ($autoStatus){
			    //这里删除产品库记录
				$str="delete from get_Product_Fromt_Lib where account='$ac' and remoteid in ($product_ids)";
				$GLOBALS['le']->query($str);
				$str="insert get_Product_Fromt_Action set account='$ac',product_ids='$product_ids',t_get=2,rectime=now()";
				$GLOBALS['le']->query($str);
				$a51=array();
				$a51['status']=100;
				$a51['statustxt']="DELETE-SUCCESS";
				$a5=array($a51);
				return toXML($this->lang,$a5);				
			}
			if ($t_get!=0 && $t_get!=1) return errXML($this->err3003);
			if ($t_url){
				if (stripos($t_url,'.12301.cc')) return errXML($this->err3005);
			    if (!$this->Check_Remote_URL($t_url)) return errXML($this->err3001);			  
			}
			if ($t_notice_url){
				if (stripos($t_notice_url,'.12301.cc')) return errXML($this->err3005);
			    if (!$this->Check_Remote_URL($t_notice_url)) return errXML($this->err3002);			  
			}
			// if ($t_notice_url && !$this->Check_Remote_URL($t_notice_url)) return errXML($this->err3002);
			
			if ($t_url || $t_notice_url) {
				$str="select id from get_Product_Fromt_Info where account='$ac' limit 1";
				$GLOBALS['le']->query($str);
				if ($GLOBALS['le']->fetch_assoc()) {
					$setstr=" uptime=now()";
					if ($t_url) $setstr.=",t_url='$t_url'";
					if ($t_notice_url) $setstr.=",t_notice_url='$t_notice_url'";
					$str="update get_Product_Fromt_Info set $setstr where account='$ac' limit 1";
				}else{
					if (!$t_url || !$t_notice_url) return errXML($this->err3004);
					$str="insert get_Product_Fromt_Info set t_url='$t_url',t_notice_url='$t_notice_url',account='$ac',rectime=now()";
				}
				$GLOBALS['le']->query($str);		
			}

			//处理产品抓取记录
			$str="insert get_Product_Fromt_Action set account='$ac',product_ids='$product_ids',t_get='$t_get',rectime=now()";
			$GLOBALS['le']->query($str);

			//处理外部抓取产品库 get_Product_Fromt_Lib
			$arr_prids=explode(',',$product_ids);
			foreach ($arr_prids as $v){
				$str="select id from get_Product_Fromt_Lib where account='$ac' and remoteid='$v' limit 1";
				$GLOBALS['le']->query($str);
				if ($GLOBALS['le']->fetch_assoc()) {
					continue;
				}else{
					$str="insert get_Product_Fromt_Lib set account='$ac',remoteid='$v',rectime=now()";
					$GLOBALS['le']->query($str);
				}
			}
			
			
			$a51=array();
			$a51['status']=100;
			$a51['statustxt']="SUCCESS";
			$a5=array($a51);
			return toXML($this->lang,$a5);
	
		}else{
			return errXML($this->err1);
		}

    }

	public function SMS_User_Defined($ac, $pw, $sms_account, $sms_pwd, $tel, $msg) {
		if ($this->authrize($ac, $pw)){
		
		$this->logrec("SMS_User_Defined#ac:$ac, pw:$pw, sms_account:$sms_account, sms_pwd:$sms_pwd, tel:$tel, msg:$msg");
			
			$URL_bak='http://userinterface.vcomcn.com/Opration.aspx';
			$URL='http://fzif.chinavcom.cn/Opration.aspx';
			$pwd=strtoupper(md5($sms_pwd));
			$account=$sms_account;
			// $ctime=date("Y-m-d H:i:s",time());
			$ctime='';
	
			$content=iconv("UTF-8","GBK",$msg);
	
			$data="<Group Login_Name='$account' Login_Pwd='$pwd' OpKind='0' InterFaceID='0'> 
				<E_Time>".$ctime."</E_Time>  
				<Item> 
					<Task> 
						<Recive_Phone_Number>".$tel."</Recive_Phone_Number>  
						<Content><![CDATA[".$content."]]></Content> 
						<Search_ID>$order_no</Search_ID>  
					</Task> 
				</Item>
			</Group>";
		
			$srv_ip_bak = 'userinterface.vcomcn.com';
			$srv_ip = 'fzif.chinavcom.cn';
			$srv_port = 80;//端口
			$url =$URL;
			$fp = '';
			$errno = 0;//错误处理 
			$errstr = '';//错误处理
			$timeout = 5;//多久没有连上就中断
			$post_str = $data;//要提交的内容
			$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
			if (!$fp) {
				$fp = fsockopen($srv_ip_bak,$srv_port,$errno,$errstr,$timeout);
				if (!$fp) return -1;//echo('fp fail');	
			}
			else $url =$URL_bak;
			
			$content_length = strlen($post_str);
			$post_header = "POST $url HTTP/1.1\r\n"; 
			$post_header.= "Content-Type: application/x-www-form-urlencoded\r\n"; 
			$post_header.= "User-Agent: MSIE\r\n";
			$post_header.= "Host: ".$srv_ip."\r\n";
			$post_header.= "Content-Length: ".$content_length."\r\n";
			$post_header.= "Connection: close\r\n\r\n";
			$post_header.= $post_str."\r\n\r\n";
			
			fwrite($fp,$post_header);
			$inheader = 1;
			
			$num=-33;
			while(!feof($fp)){
				$line = fgets($fp,1024);
				if ($inheader && ($line == "\n" || $line == "\r\n")) $inheader = 0;
				if ($inheader == 0) { 
					if ($line=='00') $num=1;
					else $num=-33;
				} 
			}
			fclose($fp);
			unset ($line); 
	
			if ($num>0) {
				$a51=array();
				$a51['status']=100;
				$a51['statustxt']="SUCCESS";
				$a5=array($a51);
				return toXML($this->lang,$a5);
			}else{
				return errXML($num);
			}
		}else{
			return errXML($this->err1);
		}
    }	

//这里自助取票回调接口 1订单号 2状态(0或1)
	public function UPD_Order_Print_Status($ac, $pw, $orderID, $status) {
		if ($this->authrize($ac, $pw)){
			$this->logrec("UPD_Order_Print_Status#ac:$ac, pw:$pw, orderID:$orderID, status:$status");
			if ($this->ac_qx!=1) return errXML($this->err4003);
			if (!is_numeric($status)) return errXML($this->err3);
			if ($status>10 || $status<0) return errXML($this->err3);
			$str="select lid from uu_ss_order where ordernum='$orderID' limit 1";
			$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err4004);
			else $lid=$GLOBALS['le']->f('lid');
			
			$str="select id from pft_member where account='$ac' limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$id=$GLOBALS['le']->f('id');		
			
			$str="select id from uu_land where id=$lid and apply_did='$id' limit 1";
			$GLOBALS['le']->query($str);
			if (!$GLOBALS['le']->fetch_assoc()) return errXML($this->err4004);
			
			$str="update uu_order_addon set ifprint=$status where orderid='$orderID' limit 1";
			$GLOBALS['le']->query($str);
			
			$a51=array();
			$a51['status']=100;
			$a51['statustxt']="SUCCESS";
			$a5=array($a51);
			return toXML($this->lang,$a5);
		}else{
			return errXML($this->err1);
		}
    }

/***********这里是函数******************/
   public function stt($s, $str) {
	  $aa=explode('|',$s);
	  $rt="";
	  $i=count($aa)-1;
	  foreach ($aa as $k=>$v){
		if ($v<0 || $v>9) {
		  return false;
		  break;
		}else{
		  if ($k==0) $rt.=" and($str='$v'";
		  else $rt.=" or $str='$v'";
		  if ($k==$i) $rt.=")";
		}
	  }
	  return $rt;
	}

	
   public function get_ids_match($mids,$aids) {	  
	$rt="";
	$arr_new=array();
	$amids=explode('|',$mids);
	$aaids=explode('|',$aids);
	if ($mids && $aids) {		
		foreach ($amids as $val){
			foreach ($aaids as $v){
				$arr_new[]=array(0=>$v,1=>$val,2=>"'".$v.",".$val."'");
			}
		}
		
		foreach ($arr_new as $k=>$v) {
			if ($k!=0) $rt.=" or ";
			$rt.="((s.member=".$v[1]." and s.aid=".$v[0].") or ids_match(".$v[2].",fd.aids)>0)";
		}
		//$rt.="$str1=$v or find_in_set($v,$str2)>$num";
	}elseif ($mids) {
		foreach ($amids as $k=>$v){
			if ($k!=0) $rt.=" or ";
			$rt.="((s.member=".$v.") or ids_match(".$v.",fd.aids)>0)";
		}
	}elseif ($aaids) {
		foreach ($aaids as $k=>$v){
			if ($k!=0) $rt.=" or ";
			$rt.="((s.aid=".$v.") or ids_match(".$v.",fd.aids)>0)";
		}
	}
	  return " and ($rt)";
	}

	public function Send_SMS_V($tel, $msg, $order_no=-1, $account=NULL) {
		$URL_bak='http://userinterface.vcomcn.com/Opration.aspx';
		$URL='http://fzif.chinavcom.cn/Opration.aspx';
		$pwd = strtoupper(md5("ab8888"));
		$account=$account?$account:"fzpft";
		// $ctime=date("Y-m-d h:i:s",time());
		$ctime='';

		$content=iconv("UTF-8","GBK",$msg);

		$data="<Group Login_Name='$account' Login_Pwd='$pwd' OpKind='0' InterFaceID='0'> 
			<E_Time>".$ctime."</E_Time>  
			<Item> 
				 <Task> 
					<Recive_Phone_Number>".$tel."</Recive_Phone_Number>  
					<Content><![CDATA[".$content."]]></Content> 
					<Search_ID>$order_no</Search_ID>
				 </Task> 
			</Item>
		</Group>";
      
		$srv_ip_bak = 'userinterface.vcomcn.com';
		$srv_ip = 'fzif.chinavcom.cn';
		$srv_port = 80;//端口
		$url =$URL;
		$fp = '';
		$errno = 0;//错误处理 
		$errstr = '';//错误处理
		$timeout = 5;//多久没有连上就中断
		$post_str = $data;//要提交的内容
		$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
		if (!$fp) {
			$fp = fsockopen($srv_ip_bak,$srv_port,$errno,$errstr,$timeout);
			if (!$fp) return -1;//echo('fp fail');	
		}
		else $url =$URL_bak;
		
		$content_length = strlen($post_str);
		$post_header = "POST $url HTTP/1.1\r\n"; 
		$post_header.= "Content-Type: application/x-www-form-urlencoded\r\n"; 
		$post_header.= "User-Agent: MSIE\r\n";
		$post_header.= "Host: ".$srv_ip."\r\n";
		$post_header.= "Content-Length: ".$content_length."\r\n";
		$post_header.= "Connection: close\r\n\r\n";
		$post_header.= $post_str."\r\n\r\n";
		
		fwrite($fp,$post_header);
		$inheader = 1;
		
		$num=-33;
		while(!feof($fp)){
			$line = fgets($fp,1024);
			if ($inheader && ($line == "\n" || $line == "\r\n")) $inheader = 0;
			if ($inheader == 0) { 
				if ($line=='00') $num=1;
				else $num=-33;
			} 
		}
		fclose($fp);
		unset ($line); 

		if ($num>0) {
		return 100;
		}else{
		return $num;
		}
    }
	
//[综合]动态价格获取（产品ID，日期，模式[0XML 1单个价格 2单个最低价]，开始时间，结束时间，类型[0供应价 1零售价]）说明：时间段价格$date,$mode必须为默认空值并会跨时间集，是否需要获取库存1需要
	public function get_Dynamic_Price_Merge($pid, $date='', $mode=0, $sdate='', $edate='', $ptype=0, $get_storage=0) {
		//if ($this->authrize($ac, $pw)){
		if (is_numeric($pid)===false) return "error1";
		$this->logrec("get_Dynamic_Price_Merge#TIGER#");
		
		require_once("/var/www/html/new/conf/pft_tiger.ll"); 
		$Tiger=new Tsql();
		$Tiger->connect();

		//取单个价格
		$onday=date('w',strtotime($date));
		if ($mode==1 && $date){
			//特殊日价格
			$q_s_price=($ptype==0)?'s_price':'l_price as s_price';
			$str="select $q_s_price,storage from uu_product_price where start_date<='$date' and end_date>='$date' and pid=$pid and ptype=1 and string_bj(weekdays,$onday)=1 order by id desc limit 1";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$s_price=$Tiger->f('s_price');
			$storage=$Tiger->f('storage');
			if (is_numeric($s_price)) {
				if ($get_storage==1) return "$s_price,$storage";
				else return $s_price;
			}

			$q_s_price=($ptype==0)?'n_price':'l_price as n_price';
			$str="select $q_s_price,storage from uu_product_price where start_date<='$date' and end_date>='$date' and pid=$pid and ptype=0 and string_bj(weekdays,$onday)=1 order by id desc limit 1";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$n_price=$Tiger->f('n_price');
			$storage=$Tiger->f('storage');
			if (is_numeric($n_price)) {
				if ($get_storage==1) return "$n_price,$storage";
				else return $n_price;
			}

			return -1;
		}elseif($mode==2){
			//单个有效最低价
			$q_s_price=($ptype==0)?'s_price':'l_price';
			$str="select min($q_s_price) as mp from uu_product_price where date_add(end_date,interval 1 day)>now() and ptype=1 and pid=$pid and $q_s_price>=0";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$mp=$Tiger->f('mp');

			$q_s_price=($ptype==0)?'n_price':'l_price';
			$str="select min($q_s_price) as np from uu_product_price where date_add(end_date,interval 1 day)>now() and ptype=0 and pid=$pid and $q_s_price>=0";
			$Tiger->query($str);
			$Tiger->fetch_assoc();
			$np=$Tiger->f('np');

			if ($mp===NULL && $np!==NULL) $lp=$np;
			elseif ($np===NULL && $mp!==NULL) $lp=$mp;
			elseif ($mp!==NULL && $np!==NULL) $lp=($mp>$np)?$np:$mp;
			//if (is_numeric($lp) && $lp>=0) return $lp;
			else $lp=-1;
			return $lp;
		}else{
			$str="select id,pid,ptype,n_price,s_price,l_price,start_date,end_date,memo,weekdays,storage from uu_product_price where pid=$pid";
			if ($sdate!=='' && $edate!=='') $str.=" and greatest(start_date,'$sdate')<=least(end_date,'$edate')";
			$str.=" order by id desc";
			//$a5[]=array("fprice"=>$fprice);
        	$Tiger->query($str);
			while ($row=$Tiger->fetch_assoc()){
				$a5[]=$row;
			}
			return toXML($this->lang,$a5);
		}

		//}else{
		//return errXML($this->err1);
		//}

    }

//实时库存查询 商品tid,查询类别（1每日实时库存2实时总库存）,查询时间串逗号分割（例如：2013-09-20,2013-09-21[类别为1时需要]）,总库存启用时间[类别为2时需要], 0返回XML1返回字符串
	public function Dynamic_Storage_Check($tid, $dtype, $times=NULL, $nowdate=NULL, $XMLC=0) {
		//if ($this->authrize($ac, $pw)){
		if (!$tid) return errXML($this->err11);

		//每日库存
		if ($dtype==1){
			$ar1=explode(',',$times);
			$axml=array();
			//每日实时库存
			foreach ($ar1 as $k=>$v){
				$str="select sum(tnum) as cc from uu_ss_order s left join uu_order_fx_details fx on s.ordernum=fx.orderid where s.begintime='$v' and s.tid='$tid' and fx.pay_status<>2 and (s.status=0 or s.status=1 or s.status=6)";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$cc=$GLOBALS['le']->f('cc');

				$axml[]=$v."|".$cc;
			}
			$xstring=implode(',',$axml);
		}elseif ($dtype==2){
			//$axml=array();
			//实时总库存
			$str="select sum(tnum) as cc from uu_ss_order s left join uu_order_fx_details fx on s.ordernum=fx.orderid where s.begintime>='$nowdate' and s.tid='$tid' and fx.pay_status<>2 and (s.status=0 or s.status=1 or s.status=6)";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$cc=$GLOBALS['le']->f('cc');

			$xstring=$cc;

		}


		if ($XMLC==0){
			$a5=array();
			$a5[]=array("Xstr"=>$xstring);
			return toXML($this->lang,$a5);
		}else{
			return $xstring;
		}



		//}else{
		//return errXML($this->err1);
		//}

    }

	function sms_qrcode_url($n){
		$na=array("u","l","5","4","3","2","1","y","s","t");
		$n=(string)$n;
		$s="";
		$len=strlen($n);
		for ($i=0;$i<$len;$i++){
			$s.=$na[$n{$i}];
		}
		return $s;
	}

	public function PFT_Coupon_Pre_Check($pid, $member, $aid, $playtime='', $tnum=0) {
		if (!$pid || !$member || !$aid) return 103;
		$errC=0;
		$str="select id from uu_products where id='$pid' and apply_limit=1 and p_status=0 limit 1";
		$GLOBALS['le']->query($str);
		if (!$GLOBALS['le']->fetch_assoc()) return 901;
		// 首先检查分销商的购买权限
		$str="select id,landid,title,delaydays,ddays,apply_did,storage_open,storage from uu_jq_ticket where pid='$pid' limit 1";
		$GLOBALS['le']->query($str);
		if (!$atk=$GLOBALS['le']->fetch_assoc()) return 901;
		// $pre_aid:原始供应商
		$pre_aid=$atk['apply_did'];
		$tid=$atk['id'];
		$storage_open=$atk['storage_open'];
		$lid=$atk['landid'];
		$storage=$atk['storage'];
		
		//如果是直接供应，判断是否可以购买此供应商下的产品
		if ($member!=$pre_aid && $pre_aid==$aid){
			$str="select pids from pft_product_sale_list where fid='$member' and aid='$pre_aid' and status=0 limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$pids=$GLOBALS['le']->f('pids');
			if ($pids!='A'){
				$a_pids=explode(',',$pids);
				if (!in_array($pid,$a_pids)) return 902;
			}	
		}
		
		//如果是转分销，判断是否可以购买
		if ($aid!=$pre_aid){
			$str="select aids from pft_p_apply_evolute where pid='$pid' and fid='$member' and sid='$aid' and status=0 limit 1";
			$GLOBALS['le']->query($str);
			$GLOBALS['le']->fetch_assoc();
			$aids=$GLOBALS['le']->f('aids');
			$arr_aids=explode(',',$aids);
			if (!$aids || !in_array($aid,$arr_aids)) return 903;
		}
		
		//库存的判定
		if ($tnum>0 && $playtime){
			$ddprice=$this->get_Dynamic_Price_Merge($pid, $playtime, 1, '', '', 0, 1);			
			if ($ddprice==-1) return 906;
			
			$a_ddprice=explode(',',$ddprice);
			$ddprice=$a_ddprice[0];
			$ddstorage=$a_ddprice[1];
			if ($ddstorage!=-1) {
				//获取实时库存消耗
				$dcstorage=$this->Dynamic_Storage_Check($tid, 1, $playtime, NULL, 1);
				$a_dcstorage=explode('|',$dcstorage);
				$d_cstorage=$a_dcstorage[1];
				$d_cstorage=(int)$d_cstorage+$tnum;
				
				if ($d_cstorage>$ddstorage) return 907;			
			}
			
			if ($storage!=-1){
				//获取实时总库存消耗
				$t_storage=$this->Dynamic_Storage_Check($tid, 2, NULL, $storage_open, 1);	
				$t_storage=(int)$t_storage+$tnum;
				if ($t_storage>$storage) return 908;			
			}
		}
		
		//提前预订时间的判定
		if ($atk['ddays']!=0){
			$nowtime=strtotime(date('Y-m-d'));
			$ddays=$atk['ddays'];
			$excepttime=strtotime("+$ddays days",$nowtime);
			$s_playtime=strtotime($playtime);
			
			if ($s_playtime<$excepttime) return 904;
			if ($s_playtime==$excepttime){
				$str="select dhour from uu_land_f where pid='$pid'";
				$GLOBALS['le']->query($str);
				$GLOBALS['le']->fetch_assoc();
				$dhour=$GLOBALS['le']->f('dhour');
				$nowhour=date("H:i:s");
				if ($dhour<$nowhour) return 905;
			}	
		}
		
		//如果是套票开始子票的判定
		$str="select p_type,attribute from uu_land where id='$lid' limit 1";
		$GLOBALS['le']->query($str);
		$GLOBALS['le']->fetch_assoc();
		$p_type=$GLOBALS['le']->f('p_type');
		$attribute=$GLOBALS['le']->f('attribute');
		
		//"pid":"2353","num":"1","lid":"2619","aid":"1433"
		if ($p_type=='F' && $attribute){
			$attr_array=json_decode($attribute,true);
			foreach ($attr_array as $val){
				$str="select id from uu_products where id='".$val['pid']."' and apply_limit=1 and p_status=0 limit 1";
				$GLOBALS['le']->query($str);
				if (!$GLOBALS['le']->fetch_assoc()) return "909|".$val['pid'];
				// 检查子票供应商的购买权限
				$str="select id,landid,title,delaydays,ddays,apply_did,storage_open,storage from uu_jq_ticket where pid='".$val['pid']."' limit 1";
				$GLOBALS['le']->query($str);
				if (!$GLOBALS['le']->fetch_assoc()) return "909|".$val['pid'];
				$C_apply_did=$GLOBALS['le']->f('apply_did');
				$C_tid=$GLOBALS['le']->f('id');
				$C_storage_open=$GLOBALS['le']->f('storage_open');
				$C_ddays=$GLOBALS['le']->f('ddays');
				$C_storage=$GLOBALS['le']->f('storage');
				$C_aid=$val['aid'];
				
				//子票直接供应的购买权限		
				if ($pre_aid!=$C_apply_did && $C_apply_did==$C_aid){
					$str="select pids from pft_product_sale_list where fid='$pre_aid' and aid='$C_apply_did' and status=0 limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$C_pids=$GLOBALS['le']->f('pids');
					if ($C_pids!='A'){
						$C_a_pids=explode(',',$C_pids);
						if (!in_array($val['pid'],$C_a_pids)) return "910|".$val['pid'];
					}	
				}
		
				//子票转分销判断是否可以购买
				if ($C_aid!=$C_apply_did){
					$str="select aids from pft_p_apply_evolute where pid='".$val['pid']."' and fid='$pre_aid' and sid='$C_aid' and status=0 limit 1";
					$GLOBALS['le']->query($str);
					$GLOBALS['le']->fetch_assoc();
					$C_aids=$GLOBALS['le']->f('aids');
					$C_arr_aids=explode(',',$C_aids);
					if (!$C_aids || !in_array($C_aid,$C_arr_aids)) return "911|".$val['pid'];//.",C_aid:$C_aid,C_aids:$C_aids";
				}
		
				//子票库存的判定
				if ($tnum>0 && $playtime){
					$C_ddprice=$this->get_Dynamic_Price_Merge($val['pid'], $playtime, 1, '', '', 0, 1);			
					if ($C_ddprice==-1) return "912|".$val['pid'];
					
					$C_a_ddprice=explode(',',$C_ddprice);
					$C_ddprice=$C_a_ddprice[0];
					$C_ddstorage=$C_a_ddprice[1];
					if ($C_ddstorage!=-1) {
						//获取实时库存消耗
						$C_dcstorage=$this->Dynamic_Storage_Check($C_tid, 1, $playtime, NULL, 1);
						$C_a_dcstorage=explode('|',$C_dcstorage);
						$C_d_cstorage=$C_a_dcstorage[1];
						$C_d_cstorage=(int)$C_d_cstorage+$tnum*$val['num'];
						
						if ($C_d_cstorage>$C_ddstorage) return "913|".$val['pid'];			
					}
					
					if ($C_storage!=-1){
						//获取实时总库存消耗
						$C_t_storage=$this->Dynamic_Storage_Check($C_tid, 2, NULL, $C_storage_open, 1);	
						$C_t_storage=(int)$C_t_storage+$tnum*$val['num'];
						if ($C_t_storage>$C_storage) return "914|".$val['pid'];				
					}
				}		
				
				//子票提前预订时间的判定
				if ($C_ddays!=0){
					$C_nowtime=strtotime(date('Y-m-d'));
					$C_excepttime=strtotime("+$C_ddays days",$C_nowtime);
					$C_s_playtime=strtotime($playtime);
					
					if ($C_s_playtime<$C_excepttime) return "915|".$val['pid'];	
					if ($C_s_playtime==$C_excepttime){
						$str="select dhour from uu_land_f where pid='".$val['pid']."'";
						$GLOBALS['le']->query($str);
						$GLOBALS['le']->fetch_assoc();
						$C_dhour=$GLOBALS['le']->f('dhour');
						$C_nowhour=date("H:i:s");
						if ($C_dhour<$C_nowhour) return "916|".$val['pid'];	
					}	
				}
			}
		}
		return 200;
	}
	
    public function Check_Remote_URL($url)
	{
        $curl=curl_init($url);
        curl_setopt($curl, CURLOPT_NOBODY, true);
        $result=curl_exec($curl);
        $found=false;
        if ($result!==false) {
            $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
            if ($statusCode==200) $found=true;   
			curl_close($curl);     
			return $found;
		}
    }
/* 分销联盟会员折扣 */
	public function PFT_D_Union_ZK($fid /*发起人ID*/, $mid /*分销商ID*/){
		
		$str="select dprice_zk from pft_union_member_info where fid='$fid' and memberID='$mid' and dstatus=0 limit 1";
		$GLOBALS['le']->query($str);
		if ($GLOBALS['le']->fetch_assoc()) $dprice_zk=$GLOBALS['le']->f('dprice_zk');
		else $dprice_zk='NONE';
		return $dprice_zk;
		
	}

/* （外部接口）分销联盟会员折扣 第二版 */
	public function PFT_D_Union_ZK_SE($fid /*发起人ID*/, $mid /*分销商ID*/){
		
		$str="select id from pft_union_member_info_SE where fid='$fid' and memberID='$mid' and dstatus=0 limit 1";
		$GLOBALS['le']->query($str);
		if ($GLOBALS['le']->fetch_assoc()) return true;
		else return false;
		
	}

	public function Make_Qrcode($Tcode){
		$rs=rand(0,6);
		$Tcode1=substr($Tcode,0,$rs);
		$Tcode2=substr($Tcode,$rs,(6-$rs));
		$rs1=rand(0,9);
		return $Tcode1.$rs1.$Tcode2.$rs;
	}
	
	public function err($txt){
		$txt=date("Y-m-d H:i:s")."|$txt";
		$fp = fopen("/mnt/log/ddbug.txt","a");
		flock($fp, LOCK_EX);
		fwrite($fp,$txt."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}

	public function logrec($word){
		$filepath="/mnt/log/ddbugSS.txt";
		$RemoteADDR=$_SERVER['REMOTE_ADDR'];
		$word=date("Y-m-d H:i:s")."|$RemoteADDR|".$word;
		$word=mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen($filepath,"a");
			flock($fp, LOCK_EX) ;
			fwrite($fp,"\n".$word);
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}

/*这里是函数结束*/

}

$kk=new PFT_server;
echo $kk->Order_Globle_Search(100019,'jjl4yk11f82ce6c0f33a5c003f2fec56',
			"601075","","","","",
			"","","","","",
			"","","","","",
			"","","","","",
			"","","","","",
			"","","","","253715",
			""
		);
// echo $kk->Get_Ticket_List(200766,'49e76fcd8cc985ece5f6c5cd23b1b953',4891,"");
// echo $kk->Get_ScenicSpot_Info(519844,'36e14e47435bfc8bead4e472be90e26b',6420,"");
// echo $kk->Get_ScenicSpot_List(100019,'jjl4yk11f82ce6c0f33a5c003f2fec56',"","");
// $server=new SoapServer("MXSE.wsdl",array('encoding' =>'UTF-8','cache_wsdl' => 0));
// $server->setClass("PFT_server");
// $server->handle();
?>